我使用的是使用maven、spring和aspectj的编译时编织。
我的aspectj顾问如下所示
@Aspect
public class LoggingInterceptor {
private LogManager logManager;
public void setLogManager(LogManager logManager) {
this.logManager = logManager;
}
.....
} 我的applicationContext.xml看起来像这样
<!--configures the AspectJ aspect and indicates which Spring context should be used when giving advice-->
<context:spring-configured />
<aop:aspectj-autoproxy/>
<!--<context:component-scan base-package="com.reverb" />-->
<bean id="loggingInterceptor" class="com.myapp.interceptor.LoggingInterceptor">
<property name="logManager" ref="logManager" />
</bean>logManager始终为null...
发布于 2011-01-25 02:41:22
我没有看到你的logManager在任何地方被定义。即使是这样,@Aspect也不会自动符合注入条件。实际上,您有两个对象-一个是LoggingInterceptor类型的bean,另一个是aspect,它实际处理AOP。但是方面不是一个bean。
为了实现这一点,你需要为你的<bean>定义factory-method="aspectOf"。有关更多信息,请访问See here。
发布于 2017-10-06 20:17:28
使用java配置,它将如下所示:
@Configuration
@EnableSpringConfigured
public class AspectConfig {
}别忘了:
@Configurable annotation 在方面:
@Aspect
@Configurable
public class CounterAspect {
@Inject
private CounterService counter;
//...
} 'org.springframework:spring-aspects' as compile 带内容:
<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
<!-- add to debug: options="-showWeaveInfo -verbose -debug"-->
<weaver>
<include within="com..*"/>
</weaver>
<aspects>
<aspect name="com.your.package.CounterAspect"/>
</aspects>
</aspectj>使用类似于-javaagent:/path-to-aspectj/aspectjweaver-1.8.10.jar的命令启用
https://stackoverflow.com/questions/4785689
复制相似问题