Java 切入点表达式中有多个执行语句,但只有一个在工作
我试图对包“com.company.somemodule”(具有类R1、R2、…)中的代码以及子包中的代码的性能进行计时Java 切入点表达式中有多个执行语句,但只有一个在工作,java,spring-aop,Java,Spring Aop,我试图对包“com.company.somemodule”(具有类R1、R2、…)中的代码以及子包中的代码的性能进行计时 com.company.somemodule.subPackageA(具有A1、A2和……类) com.company.somemodule.subPackageB 我编写的切入点与下面类似。我可以查看A1、A2类的运行时间,但无法查看R1、R2等类的运行时间 <bean id="timingAdvice" class="org.springframew
- com.company.somemodule.subPackageA(具有A1、A2和……类)
- com.company.somemodule.subPackageB
<bean id="timingAdvice"
class="org.springframework.aop.interceptor.PerformanceMonitorInterceptor" />
<aop:config>
<aop:advisor
pointcut="execution(* com.company.somemodule..*.*(..)) OR
execution(* com.company.somemodule.*.*(..))"
advice-ref="timingAdvice" />
</aop:config>
.乍一看,您的切入点没有任何错误,但我认为您需要的是结合使用“in”切入点表达式和“execution”表达式更容易完成
试着这样做:
pointcut="within(com.company.somemodule..*) AND
execution(* *(..))"
这是包com.company.somemodule中所有方法执行的切入点。以K.C.的答案为基础
我在配置Spring PerformanceMonitorInterceptor时遇到了类似的问题。下面是一个示例工作配置,我用于在几个包中监视方法执行:
<bean id="performanceMonitor"
class="org.springframework.aop.interceptor.PerformanceMonitorInterceptor" />
<aop:config>
<aop:pointcut id="allCoreMethods" expression="
(
within( org.somepackage.dao..* )
or within( org.somepackage.controller..* )
or within( org.somepackage.service..* )
or within( org.somepackage.webservices..* )
)
AND execution(* *(..))"
/>
<aop:advisor pointcut-ref="allCoreMethods" advice-ref="performanceMonitor" order="2"/>
</aop:config>