Announcement Announcement Module
Collapse
No announcement yet.
M3 <context:component-scan> and @Aspect don't work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • M3 <context:component-scan> and @Aspect don't work

    When I use <context:component-scan combined with @Aspect I'm getting circular references errors:

    Code:
    ERROR [main] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myManagerImpl': Injection of resource fields failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'otherManagerImpl': Bean with name 'otherManagerImpl' has been injected into other beans [myManagerImpl] in its raw version as part of a circular reference, but has eventually been wrapped (for example as part of auto-proxy creation). This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
    MyManagerImpl
    Code:
    @Component
    package bizservices.springtest.core.impl;
    
    import bizservices.springtest.core.OtherManager
    
    public class MyManagerImpl implements MyManager {
    
    	@Resource
    	private OtherManager otherManagerImpl;
    
    	// It is not necessary with @Component
    	public void setOtherManagerImpl(OtherManager otherManagerImpl) {
    		this.otherManagerImpl = otherManagerImpl;
    	}
    }
    OtherManagerImpl
    Code:
    package bizservices.springtest.core.impl;
    
    @Component
    public class OtherManagerImpl implements OtherManager {
    	public String helloOtherWorld() {
    		return "Hello Other World";
    	}
    }
    TestAspect:
    Code:
    @Aspect
    package bizservices.springtest.aop;
    
    public class TestAspect {
    
        @Before("within(bizservices.springtest.core..*)")
        public void log() {
            System.out.println("service invocation");
        }
    }
    applicationContext.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:context="http://www.springframework.org/schema/context"
               xmlns:aop="http://www.springframework.org/schema/aop"       
               xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.1.xsd http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
    
    	<bean id="testAspect" class="bizservices.springtest.aop.TestAspect"/>
    
    	<context:component-scan base-package="bizservices" />
    
    	<aop:aspectj-autoproxy/>
    </beans>
    If I change applicationContext.xml to declare the beans instead of use <context:component-scan> everthing works fine:

    new applicationContext.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:aop="http://www.springframework.org/schema/aop"       
               xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
    
    	<bean id="testAspect" class="bizservices.springtest.aop.TestAspect"/>
    
    	<bean id="myManagerImpl" class="bizservices.springtest.core.impl.MyManagerImpl" autowire="byName"/>
    	<bean id="otherManagerImpl" class="bizservices.springtest.core.impl.OtherManagerImpl"/>
    
    	<aop:aspectj-autoproxy/>
    </beans>
    Am I doing something wrong?

    Thanks!
    Last edited by leopinho; Aug 30th, 2007, 03:42 PM.

  • #2
    I've found the problem and created a JIRA request with the solution:
    http://opensource.atlassian.com/proj...rowse/SPR-3826

    Comment

    Working...
    X