sometimes it is nice to treat code as a blackbox and check your inputs and
outputs. but maybe thats just me. if someone changed the default value of id
attr in the annot you would get a bean not found exception, where as the
code below wouldve caught it. but whatever. i am done arguing this.
-igor
On 3/17/07, Eelco Hillenius <[EMAIL PROTECTED]> wrote:
On 3/17/07, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
> 1) make sure the default value of the springbean annot id property is
either
> null or an empty string
SpringBeanLocator#getBeanName:
public final String getBeanName()
{
if (beanName == null || "".equals(beanName))
{
beanName = getBeanNameOfClass(getSpringContext(),
getBeanType());
}
return beanName;
}
where getBeanNameOfClass always returns a non-null, non-empty value,
right?
Then the test:
assertTrue(locator.getBeanName() == null
|| locator.getBeanName().length() == 0);
doesn't make sense to me.
What Martijn added today is the || "".equals(beanName) part, which
fixed exceptions like:
ERROR - RequestCycle - No bean named '' is defined
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
bean named '' is defined
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition
(DefaultListableBeanFactory.java:355)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition
(AbstractBeanFactory.java:800)
at
org.springframework.beans.factory.support.AbstractBeanFactory.isSingleton(
AbstractBeanFactory.java:343)
at
org.springframework.context.support.AbstractApplicationContext.isSingleton
(AbstractApplicationContext.java:654)
at wicket.spring.SpringBeanLocator.isSingletonBean(
SpringBeanLocator.java:126)
at
wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getFieldValue(
AnnotProxyFieldValueFactory.java:92)
at wicket.injection.Injector.inject(Injector.java:108)
at wicket.injection.ConfigurableInjector.inject(
ConfigurableInjector.java:40)
at wicket.injection.ComponentInjector.onInstantiation(
ComponentInjector.java:53)
at wicket.Application.notifyComponentInstantiationListeners(
Application.java:920)
at wicket.Component.<init>(Component.java:568)
at wicket.MarkupContainer.<init>(MarkupContainer.java:110)
at wicket.Page.<init>(Page.java:201)
at wicket.markup.html.WebPage.<init>(WebPage.java:96)
at wicket.spring.common.web.BasePage.<init>(BasePage.java:28)
at wicket.spring.common.web.ContactsDisplayPage.<init>(
ContactsDisplayPage.java:34)
at wicket.spring.annot.web.AnnotPage.<init>(AnnotPage.java:29)
.... etc
This bug seems to have been introduced because of the recent Spring
singleton thingy.
Another interesting thing about the test is that the SpringBean
annotation's name field has a default value of "" (empty string), so
getBeanName would never return null and getBeanNameOfClass would never
been called in that method when no name was given in the annotation.
That would later on be triggered by
locateProxyTarget/lookupSpringBean.
So Martijn's fix made sense to me, whereas the test didn't.
Eelco