我正在使用JBoss 6 AS并试图通过AOP将拦截器添加到部署应用程序的某些包中的类中。这是场景:
app.jar
,其中包含我想要添加建议的类。这个JAR还有一些EJB(ejb-jar.xml,jboss.xml)。我在JBoss拦截器上创建了这样的:
package util;
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.aop.joinpoint.MethodInvocation;
public class MyInterceptor implements org.jboss.aop.advice.Interceptor {
@Override
public Object invoke(Invocation invocation) throws Throwable {
long startTime = System.currentTimeMillis();
try {
return invocation.invokeNext();
} finally {
long endTime = System.currentTimeMillis() - startTime;
System.out.println("MyInterceptor : " + endTime);
if (invocation instanceof MethodInvocation) {
MethodInvocation mi = (MethodInvocation) invocation;
String clazz = "";
String method = "";
try {
clazz = mi.getTargetObject().getClass().toString();
method = mi.getMethod().getName();
} catch (Throwable e) {
System.out.println("Error when trying to get target info");
}
System.out.println("MyInterceptor : " + endTime);
}
}
}
@Override
public String getName() {
return "MyInterceptor";
}
}
我创建了一个jboss-aop.xml
文件,其中包含:
<?xml version="1.0" encoding="UTF-8"?>
<aop xmlns="urn:jboss:aop-beans:1.0">
<interceptor name="MyInterceptor" class="util.MyInterceptor"/>
<bind pointcut="execution(* my.app.*->*(..))">
<interceptor-ref name="MyInterceptor"/>
</bind>
</aop>
我已设置enableLoadTimeWeaving
(bootstrap / aop.xml)
pluggable-instrumentor.jar
在正确的地方(JBOSS / bin)-javaagent:pluggable-instrumentor.jar
interceptor.jar
,我放了MyInterceptor.class
并在其META-INF中放置了jboss-aop.xml
文件现在,问题是,当我运行我的应用程序并且来自my.app
包中的任何类的某些方法被调用时,拦截器似乎拦截了调用,但它引发了一个讨厌的{{1} }。这是我的错误堆栈的一部分:
StackOverflowError
基本上会发生这样的情况:在java.lang.StackOverflowError
at org.jboss.resteasy.core.SynchronousDispatcher.unwrapException(SynchronousDispatcher.java:345) [:6.1.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:321) [:6.1.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:214) [:6.1.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:190) [:6.1.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:534) [:6.1.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:496) [:6.1.0.Final]
at org.jboss.resteasy.core.SynchronousDispatcher.invokePropagateNotFound(SynchronousDispatcher.java:155) [:6.1.0.Final]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:212) [:6.1.0.Final]
at org.jboss.resteasy.plugins.server.servlet.FilterDispatcher.doFilter(FilterDispatcher.java:59) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.1.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.1.0.Final]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [:6.1.0.Final]
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.1.0.Final]
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159) [:6.1.0.Final]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.1.0.Final]
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0.Final]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.1.0.Final]
at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0.Final]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.1.0.Final]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.1.0.Final]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.1.0.Final]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.1.0.Final]
at java.lang.Thread.run(Thread.java:745) [:1.7.0_79]
Caused by: java.lang.StackOverflowError
at my.app.JoinPoint_invoke_N_5164114663869737738_3.invokeJoinpoint(JoinPoint_invoke_N_5164114663869737738_3.java) [:]
at my.app.MyInterceptor$MyInterceptorAdvisor.invoke_N_5164114663869737738(MyInterceptor$MyInterceptorAdvisor.java) [:]
at my.app.MyInterceptor.invoke(MyInterceptor.java) [:]
at my.app.JoinPoint_invoke_N_5164114663869737738_3.invokeNext(JoinPoint_invoke_N_5164114663869737738_3.java) [:]
at my.app.JoinPoint_invoke_N_5164114663869737738_3.invokeJoinpoint(JoinPoint_invoke_N_5164114663869737738_3.java) [:]
at my.app.MyInterceptor$MyInterceptorAdvisor.invoke_N_5164114663869737738(MyInterceptor$MyInterceptorAdvisor.java) [:]
at my.app.MyInterceptor.invoke(MyInterceptor.java) [:]
被提升之前,这四行被抛出:
StackOverflowError
如果有人有类似的问题,任何帮助都会被指定!
答案 0 :(得分:1)
我发现了问题...我把拦截器放在同一个包my.app而不是util ...所以最终它会无休止地调用它直到堆栈已满。所以...我的坏