Java SpringAOP:注释切入点未导致执行通知
我使用的是SpringAOP(支持AspectJ注释样式),如果一个方法用特定注释(Java SpringAOP:注释切入点未导致执行通知,java,spring-aop,Java,Spring Aop,我使用的是SpringAOP(支持AspectJ注释样式),如果一个方法用特定注释(WsTransaction)注释,我希望执行代码 以下是我的观点: @Aspect @Component public class ExampleAspect { @Pointcut("execution(* example.*.ws.*.*(..))") public void isWebService() {} @Pointcut("@annotation(example.comm
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配置中有
端点由Spring创建(使用组件扫描)
批注的保留策略是运行时
Spring版本为3.0.3.发布版
我不确定哪里出了问题,或者我可以尝试调试什么
更新:SpringAOP似乎没有拾取@Endpoint注释类
更新2:AopUtils.isaoproxy(this)
和AopUtils.isglibproxy(this)
都是false
(即使使用
)我想切入点声明可能有一些问题
@Pointcut("@annotation(example.common.ws.WsTransaction)")
请参阅以了解可能的解决方案首先,我必须使用
来使用基于类(CGLIB)的代理(而不是基于Java接口的代理)
其次(这就是我遇到的问题)我必须在处理SOAP请求的servlet(MessageDispatcherServlet
)的contextConfigLocation
中指定上述内容,而不是根应用程序上下文。我尝试在切入点(@pointcut(@annotation(wsTransaction)”)中指定参数名称
并指定值和参数名),但运气不佳。同样,根据我的想法,我应该能够像以前一样使用它。上面提供的切入点在Spring中对我来说很好,同样适用于带注释的方法。