我正在使用Spring AOP(帶有AspectJ註釋樣式支持),並且想要在特定註釋(WsTransaction
)註釋方法時執行代碼。Spring AOP:不會導致建議執行的註釋切入點
這裏是我的方面:
@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
)。
註解的保留策略是運行時。
Spring版本是3.0.3.RELEASE
我不知道什麼是錯的或者我可以試着調試。
更新:看來Spring AOP的不皮卡@Endpoint註釋類
更新2:AopUtils.isAopProxy(this)
和AopUtils.isCglibProxy(this)
都false
(使用<aop:aspectj-autoproxy proxy-target-class="true"/>
即使)
我試過在切入點中指定參數名稱('@Pointcut(「@ annotation(wsTransaction)」)'並指定了值和argNames),但沒有運氣。另外根據http://static.springsource.org/spring/docs/3.0.3.RELEASE/spring-framework-reference/html/aop.html我應該可以像我一樣使用它。 –
像上面提供的切入點在Spring中對我來說工作得很好,並且帶有註釋的方法。 –