Spring Aspects 建议在 Grails 应用程序中执行两次
我有一个 grails 应用程序,并且在 grails 服务方法上添加了 @After 建议
class OrderManagementService {
static transactional = true
public void confirmOrder() {
}
}
@Aspect
public class NotVeryUsefulAspect {
@Pointcut("execution(* OrderManagementService.confirmOrder())")
public void orderManagementConfirmOrder(){}
@After("orderManagementConfirmOrder()")
public void doSomething(){
System.out.println("My First Advice is working :-)");
}
@Around("orderManagementConfirmOrder()")
public Object around(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("Around Method Invoked");
return pjp.proceed();
}
}
,但是当执行此方法时,这两个建议都会被调用两次,因此在输出中我有“
Around Method Invoked” 围绕方法调用 我的第一个建议正在发挥作用:-) 我的第一个建议正在工作:-)
我认为这与 grails 服务的 CGLIB 代理有关
,这是我
aop:aspectj-autoproxy proxy-target-class="false"
bean id="myAspect" class="org.xyz.NotVeryUsefulAspect"
aop:config proxy-target-class="true"
在 xml 内的
资源.xml任何人遇到这个并有一个解决方案使其正常工作欢呼
I have a grails app and I've added an @After advice on a grails service method
class OrderManagementService {
static transactional = true
public void confirmOrder() {
}
}
@Aspect
public class NotVeryUsefulAspect {
@Pointcut("execution(* OrderManagementService.confirmOrder())")
public void orderManagementConfirmOrder(){}
@After("orderManagementConfirmOrder()")
public void doSomething(){
System.out.println("My First Advice is working :-)");
}
@Around("orderManagementConfirmOrder()")
public Object around(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("Around Method Invoked");
return pjp.proceed();
}
}
however when this method is perform this both advices are invoked twice so in the output I have
Around Method Invoked
Around Method Invoked
My First Advice is working :-)
My First Advice is working :-)
I think this has to do with the CGLIB proxy of the grails services
this is my resource.xml
aop:aspectj-autoproxy proxy-target-class="false"
bean id="myAspect" class="org.xyz.NotVeryUsefulAspect"
aop:config proxy-target-class="true"
inside of xml
any one come across this and have a solution to make it work correctly cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论