JBoss 6与AOP一样抛出StackOverflower错误

JBoss 6与AOP一样抛出StackOverflower错误,jboss,aop,jboss6.x,Jboss,Aop,Jboss6.x,我正在使用JBoss6,并试图通过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 My

我正在使用JBoss6,并试图通过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>
    
    基本上,这四行被抛出,直到
    StackOverflowerError
    被引发:

    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) [:]
    

    如果任何人有类似的问题,任何帮助都会被上诉

    我发现了问题。。。我把拦截器放在同一个包my.app上,而不是在util中。。。因此,最终它不断地呼叫自己,直到堆栈被填满。所以我的错

    你是说JBoss EAP 6吗?我是说JBoss AS 6(社区发行版)而不是EAP 6(这将是基于JBoss AS 7的企业发行版),所以基本上JBoss 6.x IIUC?是的,这是正确的。JBoss 6.1.0要准确,当你收集了足够的声望点时,你应该能够接受自己的答案并结束这个问题。
    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) [:]