根据 Spring 的文档使用 Spring IoC 配置 AspectJ 方面以便为 Spring IOC 配置方面,必须将以下内容添加到 xml 配置中:
<bean id="profiler" class="com.xyz.profiler.Profiler"
factory-method="aspectOf">
<property name="profilingStrategy" ref="jamonProfilingStrategy"/>
</bean>
正如@SotiriosDelimanolis 所建议的那样,在 JavaConfig 中将其重写为以下内容应该可以工作:
@Bean
public com.xyz.profiler.Profiler profiler() {
com.xyz.profiler.Profiler profiler = com.xyz.profiler.Profiler.aspectOf();
profiler.setProfilingStrategy(jamonProfilingStrategy()); // assuming you have a corresponding @Bean method for that bean
return profiler;
}
但是,这似乎只有在Profiler
切面是用原生 aspectj.aj
语法编写的情况下才有效。如果它是用 Java 编写并用 注释的@Aspect
,我会收到以下错误消息:
类型 Profiler 的方法 aspectOf() 未定义
对于使用 @AspectJ 语法编写的方面,是否有使用 JavaConfig 编写此内容的等效方法?