Java Spring AOP:将CustomizableTraceInterceptor与JavaConfig @EnableAspectJAutoProxy一起使用,而不是XML< aop:advisor> [英] Java Spring AOP: Using CustomizableTraceInterceptor with JavaConfig @EnableAspectJAutoProxy, not XML <aop:advisor>

查看:90
本文介绍了Java Spring AOP:将CustomizableTraceInterceptor与JavaConfig @EnableAspectJAutoProxy一起使用,而不是XML< aop:advisor>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring AOP有一个称为CustomizableTraceInterceptor的方法级跟踪器.使用Spring的XML配置方法,可以像下面这样设置此跟踪器:

Spring AOP has a method-level tracer called CustomizableTraceInterceptor. Using Spring's XML configuration approach, one would set up this tracer like so:

<bean id="customizableTraceInterceptor" class="
  org.springframework.aop.interceptor.CustomizableTraceInterceptor">
  <property name="enterMessage" value="Entering $[methodName]($[arguments])"/>
  <property name="exitMessage" value="Leaving $[methodName](): $[returnValue]"/>
</bean>

<aop:config>
  <aop:advisor advice-ref="customizableTraceInterceptor"
    pointcut="execution(public * org.springframework.data.jpa.repository.JpaRepository+.*(..))"/>
</aop:config>

我想使用Spring的JavaConfig样式设置上述配置(即利用Java批注,尤其是@EnableAspectJAutoProxy来激活JavaConfig中的AspectJ).

I would like to set up above configuration using Spring's JavaConfig style (i.e. taking advantage of Java annotations, especially @EnableAspectJAutoProxy for activating AspectJ in JavaConfig).

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = { "some.package" })
@ComponentScan(basePackages = { "some.package2", "some.package3" })
@EnableAspectJAutoProxy
public class FacebookDomainConfiguration {

    @Bean someBean() {
    ...
    }
...
}

<aop:advisor advice-ref="customizableTraceInterceptor" ...>@EnableAspectJAutoProxy样式等效于什么?

推荐答案

不幸的是,您不能这样做,因为Java语言不支持在Spring JavaConfig中支持该方法的文字.为此打开了一个错误,但将其标记为无法修复": https://jira.springsource .org/browse/SPR-8148 .

Unfortunately, you cannot because the Java language does not support method literals which would be needed to support this in Spring JavaConfig. A bug was opened for this but marked as "Won't Fix": https://jira.springsource.org/browse/SPR-8148.

错误报告中提到的两个选项是:

The two options mentioned in the bug report are:

  1. 通过使用@ImportResource
  2. 包含相关的XML代码段,继续使用<aop:config>
  3. 将任何现有的<aop:config>元素转换为使用@Aspect样式. [这是CustomizableTraceInterceptor不可能的
  1. Continue using <aop:config> by including the relevant XML snippet using @ImportResource
  2. Convert any existing <aop:config> elemements to use @Aspect style. [which is not possible with the CustomizableTraceInterceptor]

这篇关于Java Spring AOP:将CustomizableTraceInterceptor与JavaConfig @EnableAspectJAutoProxy一起使用,而不是XML&lt; aop:advisor&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆