春天无法注入方面

use*_*201 8 spring

我正在尝试注入一个方面内的对象.但它总是无效.这个拦截器用于使用aspectj注入域对象,因此除了以下定义之外,不受spring管理

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

@Aspect
public class LoggingInterceptor {
     @Autowired
     EventLogManager eventLogManager;
 .....
}
Run Code Online (Sandbox Code Playgroud)

我的单元测试是这样的.当调用asa.execute()时,它会被LoggingInterceptor拦截,但LoggingInterceptor.eventLogManager始终为null.但下面的testInjection()工作正常.

 @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();
}
}
Run Code Online (Sandbox Code Playgroud)

我的applicationContext-service.xml具有以下内容

<bean id="eventLogManager"
    class="service.impl.EventLogDBManagerImpl">
    <property name="eventLoggingDao" ref="eventLoggingDao" />
</bean>
Run Code Online (Sandbox Code Playgroud)

我在META-INF中的aop.xml看起来像这样

<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>
Run Code Online (Sandbox Code Playgroud)

use*_*201 3

那没有用。

我用谷歌搜索了一下,在春季论坛板上找到了解决方案。链接在这里

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