user373201
user373201

Reputation: 11455

spring unable to inject in aspect

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>

Upvotes: 8

Views: 3739

Answers (1)

user373201
user373201

Reputation: 11455

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

Upvotes: 3

Related Questions