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>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With