DWR

DWR Namespace Handler causes problems with child beans for dwr:remote

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 2.0.rc2, 2.0.rc3
  • Fix Version/s: 2.0.rc4
  • Component/s: Spring
  • Description:
    Hide
    With the new RemoteBeanDefinitionDecorator that was introduced in RC3, there is a bug when trying to use the <dwr:remote> inner bean on Spring bean definitions that have a parent bean and no class attribute.

    Since DWR cannot see beans outside of its own Spring XML file, I duplicate the beans I want to expose inside the DWR spring XML file and I use the original beans as parents so as to avoid having to duplicate too much configuration:

    <bean name="dwrBeanCopy" parent="dwrBean">
        <dwr:remote javascript="dwrBean"/>
    </bean>

    When the RemoteBeanDefinitionDecorator gets to line 282, it blows up because the bean definition has no class - that comes from its parent bean.
    Show
    With the new RemoteBeanDefinitionDecorator that was introduced in RC3, there is a bug when trying to use the <dwr:remote> inner bean on Spring bean definitions that have a parent bean and no class attribute. Since DWR cannot see beans outside of its own Spring XML file, I duplicate the beans I want to expose inside the DWR spring XML file and I use the original beans as parents so as to avoid having to duplicate too much configuration: <bean name="dwrBeanCopy" parent="dwrBean">     <dwr:remote javascript="dwrBean"/> </bean> When the RemoteBeanDefinitionDecorator gets to line 282, it blows up because the bean definition has no class - that comes from its parent bean.

Activity

Hide
Brendan Grainger added a comment - 02/Apr/07 5:29 AM

I've just fixed this. Joe is there a way you can allow me to assign these bugs to myself?

Thanks
Brendan

Show
Brendan Grainger added a comment - 02/Apr/07 5:29 AM I've just fixed this. Joe is there a way you can allow me to assign these bugs to myself? Thanks Brendan
Hide
Brendan Grainger added a comment - 02/Apr/07 3:19 PM

Altered the className lookup code to look up it's parents (and it's parents etc if needed) className until one is found or there are no more parents.

Show
Brendan Grainger added a comment - 02/Apr/07 3:19 PM Altered the className lookup code to look up it's parents (and it's parents etc if needed) className until one is found or there are no more parents.
Hide
Scott Rankin added a comment - 04/Apr/07 2:09 PM

Brendan,

I just tried out your fix for DWR-37 (parent bean classname). Unfortunately, that fix doesn't quite work for my situation because in my case, the parent bean is defined in a parent BeanFactory and so doesn't show up in the BeanDefinitionRegistry from the ParserContext. I was looking through the Spring API, and there's no really good way to navigate upwards except to cast to BeanFactory to get the parent then back to BeanDefinitionRegistry to get the parent bean def.

This is what I came up with in a few minutes of hacking at it - please feel free to make it better!

private String resolveBeanClassname(BeanDefinition definition, BeanDefinitionRegistry registry)
{
String beanClassName = definition.getBeanClassName();
if (!StringUtils.hasText(beanClassName))
{
while (definition instanceof ChildBeanDefinition )
{
String parentName = ((ChildBeanDefinition)definition).getParentName();
while(registry != null && !registry.containsBeanDefinition(parentName))
{
if(registry instanceof ApplicationContext)

{ registry = (BeanDefinitionRegistry)((ApplicationContext)registry).getParent(); }

else if(registry instanceof AbstractBeanFactory)

{ registry = (BeanDefinitionRegistry)((AbstractBeanFactory)registry).getParentBeanFactory(); }

else

{ break; }

}

if(registry != null)

{ BeanDefinition parentDefinition = registry.getBeanDefinition(parentName); beanClassName = parentDefinition.getBeanClassName(); if (StringUtils.hasText(beanClassName )) break; definition = parentDefinition; }

}
}

return beanClassName;
}

Show
Scott Rankin added a comment - 04/Apr/07 2:09 PM Brendan, I just tried out your fix for DWR-37 (parent bean classname). Unfortunately, that fix doesn't quite work for my situation because in my case, the parent bean is defined in a parent BeanFactory and so doesn't show up in the BeanDefinitionRegistry from the ParserContext. I was looking through the Spring API, and there's no really good way to navigate upwards except to cast to BeanFactory to get the parent then back to BeanDefinitionRegistry to get the parent bean def. This is what I came up with in a few minutes of hacking at it - please feel free to make it better! private String resolveBeanClassname(BeanDefinition definition, BeanDefinitionRegistry registry) { String beanClassName = definition.getBeanClassName(); if (!StringUtils.hasText(beanClassName)) { while (definition instanceof ChildBeanDefinition ) { String parentName = ((ChildBeanDefinition)definition).getParentName(); while(registry != null && !registry.containsBeanDefinition(parentName)) { if(registry instanceof ApplicationContext) { registry = (BeanDefinitionRegistry)((ApplicationContext)registry).getParent(); } else if(registry instanceof AbstractBeanFactory) { registry = (BeanDefinitionRegistry)((AbstractBeanFactory)registry).getParentBeanFactory(); } else { break; } } if(registry != null) { BeanDefinition parentDefinition = registry.getBeanDefinition(parentName); beanClassName = parentDefinition.getBeanClassName(); if (StringUtils.hasText(beanClassName )) break; definition = parentDefinition; } } } return beanClassName; }
Hide
Brendan Grainger added a comment - 05/Apr/07 12:42 PM

Need to make sure parent BeanFactories are serched.

Show
Brendan Grainger added a comment - 05/Apr/07 12:42 PM Need to make sure parent BeanFactories are serched.
Hide
Brendan Grainger added a comment - 09/Apr/07 3:21 PM

Fixed. Thanks to Scott Rankin for pointing out and testing the resolution

Show
Brendan Grainger added a comment - 09/Apr/07 3:21 PM Fixed. Thanks to Scott Rankin for pointing out and testing the resolution
Hide
Fried Hoeben added a comment - 12/Dec/07 3:11 PM

Unfortunately this fix does not work for me (with Spring 2.5). My bean definition is not a ChildBeanDefinition anymore but a generic one. This can be understood reading the JavaDoc of ChildBeanDefinition in spring 2.5

  • <p><b>NOTE:</b> Since Spring 2.5, the preferred way to register bean
  • definitions programmatically is the {@link GenericBeanDefinition} class,
  • which allows to dynamically define parent dependencies through the
  • {@link GenericBeanDefinition#setParentName} method. This effectively
  • supersedes the ChildBeanDefinition class for most use cases.

My bean definition does have a parent name however (is the getParentName() new in BeanDefinition for Spring 2.5)?

Show
Fried Hoeben added a comment - 12/Dec/07 3:11 PM Unfortunately this fix does not work for me (with Spring 2.5). My bean definition is not a ChildBeanDefinition anymore but a generic one. This can be understood reading the JavaDoc of ChildBeanDefinition in spring 2.5
  • <p><b>NOTE:</b> Since Spring 2.5, the preferred way to register bean
  • definitions programmatically is the {@link GenericBeanDefinition} class,
  • which allows to dynamically define parent dependencies through the
  • {@link GenericBeanDefinition#setParentName} method. This effectively
  • supersedes the ChildBeanDefinition class for most use cases.
My bean definition does have a parent name however (is the getParentName() new in BeanDefinition for Spring 2.5)?

People

Dates

  • Created:
    29/Mar/07 7:21 PM
    Updated:
    29/Feb/08 10:29 AM
    Resolved:
    09/Apr/07 3:21 PM