8

I am trying to inject an object which is inside an aspect. But it always turns up null. this interceptor was used to inject domain objects using aspectj hence not managed by spring except the following definition

<context:load-time-weaver />
<context:component-scan base-package="framework.interceptor" />

@Aspect
public class LoggingInterceptor {
     @Autowired
     EventLogManager eventLogManager;
 .....
}

my unit test is something like this. when asa.execute() is called it gets intercepted by LoggingInterceptor, but LoggingInterceptor.eventLogManager is always null. But testInjection() below works fine.

 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(locations = {     "classpath:applicationContext-dao.xml",
                                    "classpath:applicationContext-service.xml",
                                    "classpath:applicationContext-resources.xml",
                                    "classpath:LoggingTest-context.xml"})
public class LoggingInterceptorTest {

    @Autowired
EventLogManager eventLogManager;

@Test
public void testInjection(){
    Assert.assertNotNull(eventLogManager);
}

@Test
public void testAccountSaveActionAdvice(){
    AccountSaveAction asa = new AccountSaveAction();
    asa.execute();
}
}

my applicationContext-service.xml has the following

<bean id="eventLogManager"
    class="service.impl.EventLogDBManagerImpl">
    <property name="eventLoggingDao" ref="eventLoggingDao" />
</bean>

my aop.xml in META-INF looks like this

<aspectj>
<weaver>
    <!-- only weave classes in this package -->
    <include within="action..*" />
</weaver>
<aspects>
    <!-- use only this aspect for weaving -->
    <aspect name="interceptor.LoggingInterceptor" />
</aspects>
</aspectj>

1 Answer 1

3

That did not work.

I googled a little bit and found the solution in spring forum board. Here is the link

http://forum.springsource.org/showthread.php?t=79674

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.