Skip to content

Autowiring won't work when using scopes and targetClass auto proxying [SPR-4524] #9201

Closed

Description

@spring-projects-issues

David J. M. Karlsen opened SPR-4524 and commented

java.lang.IllegalStateException: Annotation-specified bean name 'portalUserRequestData' for bean class [XXXX.PortalUserRequestData] conflicts with existing, non-compatible bean definition of same name and class [org.springframework.aop.scope.ScopedProxyFactoryBean]

I've got a PortalUserRequestData bean declared as:
@Scope( "request" )
@Component

This is then injected in another bean as following:

@Autowired
private PortalUserRequestData portalUserRequestData;

and fails with the message above.

it can be noted that if the same bean is declared in XML (with scope=) and set on the other bean in xml (with set property, and ref="portalUserRequestData").
there's no problem - thus it's probably a bug in the spring core container.


Affects: 2.5.1

Attachments:

Issue Links:

Activity

  1. spring-projects-issues commented on Feb 29, 2008

    @spring-projects-issues
    CollaboratorAuthor

    David J. M. Karlsen commented

    Added stack traces:

    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:405)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:327)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:295)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:97)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:411)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:338)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:332)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:266)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:236)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:126)
    at javax.servlet.GenericServlet.init(GenericServlet.java:256)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:191)
    at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.init(ServletWrapper.java:326)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:347)
    at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:473)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3276)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:811)
    at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1455)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:113)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:454)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:383)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:263)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
    

    Caused by: java.lang.IllegalStateException: Annotation-specified bean name 'portalUserRequestData' for bean class [XXXXXXXXX.PortalUserRequestData] conflicts with existing, non-compatible bean definition of same name and class [org.springframework.aop.scope.ScopedProxyFactoryBean]
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.checkBeanName(ClassPathBeanDefinitionScanner.java:234)
    at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:195)
    at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:159)
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1246)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1236)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:488)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:383)

  2. spring-projects-issues commented on Feb 29, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    You're apparently scanning the same package twice - maybe through multiple component-scan tags in different XML files? That sort of error just happens in that case...

    There is still a Spring bug hiding here, but just in the detection of compatible bean definitions (which are skipped even on re-scanning): It doesn't detect a scoped-proxy definition as compatible with the currently processed component class.

    Juergen

  3. spring-projects-issues commented on Feb 29, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    I've addressed this through comparing the actually registered bean definition rather than the originally scanned one. This compares apples to apples then: i.e. scoped-proxy definitions to scoped-proxy definitions, considering them as compatible.

    Juergen

  4. spring-projects-issues commented on Feb 29, 2008

    @spring-projects-issues
    CollaboratorAuthor

    David J. M. Karlsen commented

    Cool - I'll double check the config.
    Thanks for an extreamly fast fix - as always.

  5. spring-projects-issues commented on Mar 2, 2008

    @spring-projects-issues
    CollaboratorAuthor

    David J. M. Karlsen commented

    The beans are defined twice - yes.

    Once with annotations (for normal production environment) - and once again in a test-context w/o scope (to be injectable in the spring beans in our unit-tests) - the latter definition overriding the first (as the approach explained in http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/web/context/support/XmlWebApplicationContext.html)

    This approach would not be neccessary if the spring framework could provide support for beans defined with scope out of the box for unit-testing. Another approach could of course be to split the context's - one "constant" for the common configuration, one for production, and one for test - but I really want to keep configuration overhead to a minimum.

  6. spring-projects-issues commented on Jun 28, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Alex Gitelman commented

    It seems that the issue resurfaced in 2.5.5
    I just upgraded from 2.5.4 where it worked just fine and started getting this error. Once I removed scan statement from one of nested files, my tests went through ok.

  7. spring-projects-issues commented on Jun 28, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Alex Gitelman commented

    Actually I upgraded from 2.5.3 (not 2.5.4 as stated in comment). So it may have happened in 2.5.4 already - I wouldn't know.

  8. spring-projects-issues commented on Jun 29, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Reopening in lieu of Alex's comments.

  9. spring-projects-issues commented on Jul 1, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Alex, could you please submit a description of your setup there? What kind of definition is supposed to override which other kind of definition? What does the order of configuration look like? A small test case would be ideal...

    Juergen

  10. spring-projects-issues commented on Jul 1, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Alex Gitelman commented

    Here we go.

    ctx1.xml imports ctx2.xml and both scan the same package.

  11. spring-projects-issues commented on Jul 1, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Alex Gitelman commented

    Just in case - file is attached test case and maven pom to simulate the problem. Just run the build.

  12. spring-projects-issues commented on Jul 2, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    This wasn't the same issue, actually, but rather a different one that sneaked in through the fix for the previous issue: We are comparing the source objects of bean definitions now, and those were accidentally set to null by the SourceExtractor in the XML namespace parsing.

    I've fixed this for 2.5.6, so all so such cases should work fine now. This will be available in tonight's 2.5.6 snapshot (http://static.springframework.org/downloads/nightly/snapshot-download.php?project=SPR). Please give it an early try and let me know whether it works for you...

    Juergen

  13. spring-projects-issues commented on Jul 12, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Alex Gitelman commented

    I finally got around to try it with snapshot and it works.
    Thanks
    Alex

  14. spring-projects-issues commented on May 16, 2009

    @spring-projects-issues
    CollaboratorAuthor

    François Le Droff commented

    I hit the same bug when migration from spring-aop 2.5.2 to version 2.5.6
    I had to specify non overlapping packages to scan in my different application-context xml files (I did not have to do to that with version 2.5.2)

  15. added
    type: bug
    in: core
    on Jan 11, 2019
  16. added this to the 2.5.6 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions