【发布时间】:2014-09-30 23:58:19
【问题描述】:
这是我迄今为止尝试过的,我的拦截器没有被触发(我的日志中没有“TATATA”):
我的拦截器 AopLoggingInterceptor.java :
package fr.mycompany.bus.flow.reco.ani.custom.interceptor;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@Aspect
public class AopLoggingInterceptor {
@Around("execution(* org.mule.api.transport.MessageReceiver.routeMessage(org.mule.api.MuleMessage))")
public Object addMonitor(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("TATATA Before");
Object object = pjp.proceed();
System.out.println("TATATA After");
return object;
}
}
META-INF/aop.xml:
<aspectj>
<aspects>
<aspect name="fr.mycompany.bus.flow.reco.ani.custom.interceptor.AopLoggingInterceptor" />
</aspects>
<weaver options="-verbose">
<!-- Weave types that are within the org.mule.* packages. -->
<include within="org.mule.*" />
</weaver>
</aspectj>
我的 Mule/Spring 配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<mule >
<spring:beans>
<context:component-scan base-package="fr.mycompany.bus" />
<context:annotation-config />
<aop:aspectj-autoproxy />
<!-- Aspect -->
<spring:bean name="aopLoggingInterceptor" class="fr.mycompany.bus.flow.reco.ani.custom.interceptor.AopLoggingInterceptor" />
</spring:beans>
</mule>
我的 Mule 文件配置由一个流和一个入站端点、2 个出站端点、记录器和转换器组成(经过广泛测试的有效流)。
虚拟机参数:
-XX:PermSize=128M -XX:MaxPermSize=256M -javaagent:D:\path\to\mule\opt\aspectjweaver-1.6.11.jar
从 Eclipse 中开始的 mule 文件中提取显示编织已创建:
[MuleApplicationClassLoader@2934847] info AspectJ Weaver Version 1.6.11 built on Tuesday Mar 15, 2011 at 15:31:04 GMT
[MuleApplicationClassLoader@2934847] info register classloader org.mule.module.launcher.MuleApplicationClassLoader@2934847
[MuleApplicationClassLoader@2934847] info using configuration /D:/BusToolBox/workspaces/dev/.mule/apps/bus-esb-mrc-reco-ani/classes/META-INF/aop.xml
[MuleApplicationClassLoader@2934847] info register aspect fr.mycompany.bus.flow.reco.ani.custom.interceptor.AopLoggingInterceptor
编辑
它适用于我项目中包含的类,但不适用于 mule 类:
[MuleApplicationClassLoader@6ad5934d] debug generating class 'fr.mycompany.bus.flow.reco.ani.custom.transformer.CustomerDetailToSiebelRecoAniOutputTransformer$AjcClosure1'
编辑 2
这是我能得到的最好结果(通过使用<context:load-time-weaver />),加载过程试图寻找由不同类加载器加载的更多类,但结果是:
ERROR 2014-08-08 16:00:46,802 [main] org.mule.module.launcher.application.DefaultMuleApplication: null
java.lang.IllegalStateException: ClassLoader [org.mule.module.launcher.MuleApplicationClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar
如果我尝试使用 spring-instrument-3.2.1.RELEASE.jar,我会得到与以前相同的结果(只看到主类加载器)。这是否意味着骡子没有希望了?
【问题讨论】:
-
尝试一下:从 Mule/Spring 配置文件中删除所有内容(拦截器、自动代理、加载时间编织器等),将
aop.xml中的weaver属性更改为<weaver options="-debug -verbose -showWeaveInfo" />并运行-javaagent指向aspectjweaver-1.6.11.jar的应用程序。 -
我的拦截模式仅在“@Around”注释中声明,因此如果没有它,它会尝试编织他可以到达的类集(没有 mule 类)而没有成功。
标签: spring mule aspectj spring-aop