繁体   English   中英

Spring AOP:注释切入点不导致执行建议

[英]Spring AOP: Annotation pointcut not causing advice to execute

我正在使用Spring AOP(具有AspectJ注释样式支持),并且如果方法带有特定注释( WsTransaction )进行注释,则希望执行代码。

这是我的方面:

@Aspect
@Component
public class ExampleAspect {

    @Pointcut("execution(* example.*.ws.*.*(..))")
    public void isWebService() {}

    @Pointcut("@annotation(example.common.ws.WsTransaction)")
    public void isAnnotated() {}

    @Before("isWebService() && isAnnotated()")
    public void before() {
        System.out.println("before called");
    }
}

这是一个示例类,我希望它可以在其中运行:

package example.common.ws;

@Endpoint
public class SomeEndpoint {

    @WsTransaction() // I want advice to execute if this annotation present
    @PayloadRoot(localPart = "SomeRequest", namespace = "http://example/common/ws/")
    public SomeResponse methodToBeCalled(SomeRequest request) {
            // Do stuff
            return someResponse;
    }
}

当我将@Before更改为仅使用isWebService()它将被调用,但是当我使用isWebService() && isAnnotated()或只是isAnnotated()尝试时,似乎什么都没有发生。

我的Spring配置中有<aop:aspectj-autoproxy/>

端点是由Spring创建的(使用component-scan )。

注释的保留策略是运行时。

春季版本是3.0.3.RELEASE

我不确定什么是错误的,或者我可以尝试调试什么。

更新:Spring AOP似乎没有使用@Endpoint注释的类

更新2: AopUtils.isAopProxy(this)AopUtils.isCglibProxy(this)均为false (即使使用<aop:aspectj-autoproxy proxy-target-class="true"/>

首先,我必须使用<aop:aspectj-autoproxy proxy-target-class="true"/>来使用基于类的(CGLIB)代理(而不是基于Java接口的代理)。

其次(这是我遇到的问题),我必须在处理SOAP请求的servlet的contextConfigLocation中指定以上内容( MessageDispatcherServlet ),而不是在根应用程序上下文中进行指定。

我想切入点声明可能存在一些问题。

  @Pointcut("@annotation(example.common.ws.WsTransaction)")

请参阅此链接以获取可能的解决方案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM