开发者

Spring Aspects advices being performed twice in Grails App

开发者 https://www.devze.com 2023-02-13 15:25 出处:网络
I have a grails app and I\'ve added an @After advice on a grails service method class OrderManagementService {

I have a grails app and I've added an @After advice on a grails service method

class OrderManagementService {

    static transactional = true

开发者_JS百科    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

0

精彩评论

暂无评论...
验证码 换一张
取 消