Announcement Announcement Module
Collapse
No announcement yet.
Aspect and @Inject Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Aspect and @Inject

    I was attempting to inject external resources into my Aspect for my unit testing using Mocks and I found what I think is an interesting use case. When I declare the the config as follows:

    Code:
    	<context:annotation-config/>
    	<context:component-scan base-package="com.capitalone.epf.logging.aspects"/>
    	
    	<aop:aspectj-autoproxy/>
    	
    	<bean class="org.easymock.EasyMock" factory-method="createMock"
    		primary="true" id="logger">
    		<constructor-arg value="com.capitalone.epf.logging.LoggerManager" />
    	</bean>
    	
    	<bean class="org.easymock.EasyMock" factory-method="createMock"
    		primary="true" id="loggerMock">
    		<constructor-arg value="com.capitalone.epf.logging.Logger" />
    	</bean>
    I get an auto-wiring failure, but when I declare it like:

    Code:
    <bean class="org.easymock.EasyMock" factory-method="createMock"
    		primary="true" id="logger">
    		<constructor-arg value="com.capitalone.epf.logging.LoggerManager" />
    	</bean>
    	
    	<bean class="org.easymock.EasyMock" factory-method="createMock"
    		primary="true" id="loggerMock">
    		<constructor-arg value="com.capitalone.epf.logging.Logger" />
    	</bean>
    
    	<context:annotation-config/>
    	<context:component-scan base-package="com.capitalone.epf.logging.aspects"/>
    	
    	<aop:aspectj-autoproxy/>
    It works like a champ. This is in version 3.1 and prior to using @Inject order didn't seems to matter for @Resource. Any thoughts?
    Last edited by difranr; Dec 14th, 2011, 11:54 PM.

  • #2
    I did some more research and seems as if the @Resource works as expected, meaning that order doesn't matter in the Spring configuration file. But it seems to for the @Inject annotation. Any thoughts?

    Comment


    • #3
      dont be use inject just use external
      thanks for share that i am going to search about it

      Pocket Folders , Vinyl Stickers, Round Stickers

      Comment


      • #4
        Our preferred approach is to use he JSR-330 annotations so the answer is less than ideal. I did find that if we use @Configuration based approach then it works as well. So it is purely related to XML based config and @Inject.

        Comment

        Working...
        X