pointcut not working on methods with arguments@AspectJ pointcut for all methods of a class with specific annotationSpring, Aspect J, multiple AfterThrowing advice applied to the same pointcutSpring AOP Aspect not executingSpring AOP: What's the difference between JoinPoint and PointCut?How do I pass arguments to Spring AOP advice with annotated parameters?How exactly works Spring AOP context selecting pointcuts?Pointcuts on inherited methods (in a class design-agnostic context)How do you enable AspectJ to execute advice on a joinpoint called by a method of the same class?Spring AOP: How exclude an unnecessary @Pointcut (@Around advice) execution due the execution from others @Pointcuts/advicesSpring AOP: aspect @Around doesn't work

Are there categories whose internal hom is somewhat 'exotic'?

How to translate 脑袋短路 into English?

Use of vor in this sentence

Are there any OR challenges that are similar to kaggle's competitions?

What are the ramifications of this change to upcasting spells?

Is there any road between the CA State Route 120 and Sherman Pass Road (Forest Route 22S0) that crosses Yosemite/Serria/Sequoia National Park/Forest?

What can I do to keep a threaded bolt from falling out of it’s slot

Is there such a thing as too inconvenient?

How do slats reduce stall speed?

Unity: transform.LookAt(target) not "looking at" target?

How do I intentionally fragment a SQL Server Index?

Is a butterfly one or two animals?

What animal has fat with the highest energy density?

Why is su world executable?

Count the frequency of items in an array

Do living authors still get paid royalties for their old work?

Repurpose telephone line to ethernet

!I!n!s!e!r!t! !n!b!e!t!w!e!e!n!

Can a Beast Master ranger choose a swarm as an animal companion?

Land Registry Clause

Interaction between Ethereal Absolution versus Edgar Markov with Captivating Vampire

How does the Saturn V Dynamic Test Stand work?

My two team members in a remote location don't get along with each other; how can I improve working relations?

"Silverware", "Tableware", and "Dishes"



pointcut not working on methods with arguments


@AspectJ pointcut for all methods of a class with specific annotationSpring, Aspect J, multiple AfterThrowing advice applied to the same pointcutSpring AOP Aspect not executingSpring AOP: What's the difference between JoinPoint and PointCut?How do I pass arguments to Spring AOP advice with annotated parameters?How exactly works Spring AOP context selecting pointcuts?Pointcuts on inherited methods (in a class design-agnostic context)How do you enable AspectJ to execute advice on a joinpoint called by a method of the same class?Spring AOP: How exclude an unnecessary @Pointcut (@Around advice) execution due the execution from others @Pointcuts/advicesSpring AOP: aspect @Around doesn't work






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I've added an annotation to track the time it takes a method to execute, but even though it executes for methods without parameters, it does not on methods with parameters.



@Around("@annotation(com.x.y.a.TrackTime)")
public Object trackTime(ProceedingJoinPoint joinPoint) throws Throwable
return getProceedAndTrackTime(joinPoint);



I also tried using execution:



 @Around("execution(public void com.x.y.m.myMethod(..))")


also



@Around("execution(public void com.x.y.m.myMethod(com.x.y.e.SomeType))")


and also



 @Around("execution(public void com.x.y.m.myMethod(..)) && args(myArgument,..)")


None of the above works on methods with parameters, why is that? How should it be done?










share|improve this question





















  • 1





    Nobody can help you diagnose the problem if you only show pointcuts and not the target methods. I would be very surprised if what you say is true. Maybe you think it is because the methods have no parameters, but probably it is something else: They are not annotated, they are not public, they reside in classes which are no Spring beans/components etc. There are many possible reasons, your information is insufficient. As a user with 1,000+ reputation points you should know better how to ask questions. Please provide an MCVE.

    – kriegaex
    Apr 5 at 2:25


















0















I've added an annotation to track the time it takes a method to execute, but even though it executes for methods without parameters, it does not on methods with parameters.



@Around("@annotation(com.x.y.a.TrackTime)")
public Object trackTime(ProceedingJoinPoint joinPoint) throws Throwable
return getProceedAndTrackTime(joinPoint);



I also tried using execution:



 @Around("execution(public void com.x.y.m.myMethod(..))")


also



@Around("execution(public void com.x.y.m.myMethod(com.x.y.e.SomeType))")


and also



 @Around("execution(public void com.x.y.m.myMethod(..)) && args(myArgument,..)")


None of the above works on methods with parameters, why is that? How should it be done?










share|improve this question





















  • 1





    Nobody can help you diagnose the problem if you only show pointcuts and not the target methods. I would be very surprised if what you say is true. Maybe you think it is because the methods have no parameters, but probably it is something else: They are not annotated, they are not public, they reside in classes which are no Spring beans/components etc. There are many possible reasons, your information is insufficient. As a user with 1,000+ reputation points you should know better how to ask questions. Please provide an MCVE.

    – kriegaex
    Apr 5 at 2:25














0












0








0








I've added an annotation to track the time it takes a method to execute, but even though it executes for methods without parameters, it does not on methods with parameters.



@Around("@annotation(com.x.y.a.TrackTime)")
public Object trackTime(ProceedingJoinPoint joinPoint) throws Throwable
return getProceedAndTrackTime(joinPoint);



I also tried using execution:



 @Around("execution(public void com.x.y.m.myMethod(..))")


also



@Around("execution(public void com.x.y.m.myMethod(com.x.y.e.SomeType))")


and also



 @Around("execution(public void com.x.y.m.myMethod(..)) && args(myArgument,..)")


None of the above works on methods with parameters, why is that? How should it be done?










share|improve this question
















I've added an annotation to track the time it takes a method to execute, but even though it executes for methods without parameters, it does not on methods with parameters.



@Around("@annotation(com.x.y.a.TrackTime)")
public Object trackTime(ProceedingJoinPoint joinPoint) throws Throwable
return getProceedAndTrackTime(joinPoint);



I also tried using execution:



 @Around("execution(public void com.x.y.m.myMethod(..))")


also



@Around("execution(public void com.x.y.m.myMethod(com.x.y.e.SomeType))")


and also



 @Around("execution(public void com.x.y.m.myMethod(..)) && args(myArgument,..)")


None of the above works on methods with parameters, why is that? How should it be done?







aop aspectj spring-aop






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 14:44







CCC

















asked Mar 27 at 14:39









CCCCCC

1,1464 gold badges24 silver badges44 bronze badges




1,1464 gold badges24 silver badges44 bronze badges










  • 1





    Nobody can help you diagnose the problem if you only show pointcuts and not the target methods. I would be very surprised if what you say is true. Maybe you think it is because the methods have no parameters, but probably it is something else: They are not annotated, they are not public, they reside in classes which are no Spring beans/components etc. There are many possible reasons, your information is insufficient. As a user with 1,000+ reputation points you should know better how to ask questions. Please provide an MCVE.

    – kriegaex
    Apr 5 at 2:25













  • 1





    Nobody can help you diagnose the problem if you only show pointcuts and not the target methods. I would be very surprised if what you say is true. Maybe you think it is because the methods have no parameters, but probably it is something else: They are not annotated, they are not public, they reside in classes which are no Spring beans/components etc. There are many possible reasons, your information is insufficient. As a user with 1,000+ reputation points you should know better how to ask questions. Please provide an MCVE.

    – kriegaex
    Apr 5 at 2:25








1




1





Nobody can help you diagnose the problem if you only show pointcuts and not the target methods. I would be very surprised if what you say is true. Maybe you think it is because the methods have no parameters, but probably it is something else: They are not annotated, they are not public, they reside in classes which are no Spring beans/components etc. There are many possible reasons, your information is insufficient. As a user with 1,000+ reputation points you should know better how to ask questions. Please provide an MCVE.

– kriegaex
Apr 5 at 2:25






Nobody can help you diagnose the problem if you only show pointcuts and not the target methods. I would be very surprised if what you say is true. Maybe you think it is because the methods have no parameters, but probably it is something else: They are not annotated, they are not public, they reside in classes which are no Spring beans/components etc. There are many possible reasons, your information is insufficient. As a user with 1,000+ reputation points you should know better how to ask questions. Please provide an MCVE.

– kriegaex
Apr 5 at 2:25













1 Answer
1






active

oldest

votes


















1














To track the execution time of a method with or without arguments, you can try below annotation and implementation:



Annotated interface:



@Component
@Retention(RUNTIME)
@Target(ElementType.METHOD)
public @interface TimeTracker


And implementation of above interface:



@Component
@Aspect
public class TimeTrackerAspect

@Around("@annotation(TimeTracker)")
public Object around(ProceedingJoinPoint pJoinPoint) throws Throwable
Long startTime = System.currentTimeMillis();
Object obj = pJoinPoint.proceed();
System.out.println("Total milli seconds in execution of method: " + pJoinPoint.getSignature().getName() + " is :" + (System.currentTimeMillis()-startTime));
return obj;




And then wherever you use the annotation @TimeTracker total time will be printed, you can changes from sysout to logging



For details, I have also pushed my sample code into github, have a look into that at: https://github.com/krishnaiitd/learningJava/tree/master/springBoot/gs-spring-boot/src/main/java/com/example/demo






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55379917%2fpointcut-not-working-on-methods-with-arguments%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    To track the execution time of a method with or without arguments, you can try below annotation and implementation:



    Annotated interface:



    @Component
    @Retention(RUNTIME)
    @Target(ElementType.METHOD)
    public @interface TimeTracker


    And implementation of above interface:



    @Component
    @Aspect
    public class TimeTrackerAspect

    @Around("@annotation(TimeTracker)")
    public Object around(ProceedingJoinPoint pJoinPoint) throws Throwable
    Long startTime = System.currentTimeMillis();
    Object obj = pJoinPoint.proceed();
    System.out.println("Total milli seconds in execution of method: " + pJoinPoint.getSignature().getName() + " is :" + (System.currentTimeMillis()-startTime));
    return obj;




    And then wherever you use the annotation @TimeTracker total time will be printed, you can changes from sysout to logging



    For details, I have also pushed my sample code into github, have a look into that at: https://github.com/krishnaiitd/learningJava/tree/master/springBoot/gs-spring-boot/src/main/java/com/example/demo






    share|improve this answer





























      1














      To track the execution time of a method with or without arguments, you can try below annotation and implementation:



      Annotated interface:



      @Component
      @Retention(RUNTIME)
      @Target(ElementType.METHOD)
      public @interface TimeTracker


      And implementation of above interface:



      @Component
      @Aspect
      public class TimeTrackerAspect

      @Around("@annotation(TimeTracker)")
      public Object around(ProceedingJoinPoint pJoinPoint) throws Throwable
      Long startTime = System.currentTimeMillis();
      Object obj = pJoinPoint.proceed();
      System.out.println("Total milli seconds in execution of method: " + pJoinPoint.getSignature().getName() + " is :" + (System.currentTimeMillis()-startTime));
      return obj;




      And then wherever you use the annotation @TimeTracker total time will be printed, you can changes from sysout to logging



      For details, I have also pushed my sample code into github, have a look into that at: https://github.com/krishnaiitd/learningJava/tree/master/springBoot/gs-spring-boot/src/main/java/com/example/demo






      share|improve this answer



























        1












        1








        1







        To track the execution time of a method with or without arguments, you can try below annotation and implementation:



        Annotated interface:



        @Component
        @Retention(RUNTIME)
        @Target(ElementType.METHOD)
        public @interface TimeTracker


        And implementation of above interface:



        @Component
        @Aspect
        public class TimeTrackerAspect

        @Around("@annotation(TimeTracker)")
        public Object around(ProceedingJoinPoint pJoinPoint) throws Throwable
        Long startTime = System.currentTimeMillis();
        Object obj = pJoinPoint.proceed();
        System.out.println("Total milli seconds in execution of method: " + pJoinPoint.getSignature().getName() + " is :" + (System.currentTimeMillis()-startTime));
        return obj;




        And then wherever you use the annotation @TimeTracker total time will be printed, you can changes from sysout to logging



        For details, I have also pushed my sample code into github, have a look into that at: https://github.com/krishnaiitd/learningJava/tree/master/springBoot/gs-spring-boot/src/main/java/com/example/demo






        share|improve this answer













        To track the execution time of a method with or without arguments, you can try below annotation and implementation:



        Annotated interface:



        @Component
        @Retention(RUNTIME)
        @Target(ElementType.METHOD)
        public @interface TimeTracker


        And implementation of above interface:



        @Component
        @Aspect
        public class TimeTrackerAspect

        @Around("@annotation(TimeTracker)")
        public Object around(ProceedingJoinPoint pJoinPoint) throws Throwable
        Long startTime = System.currentTimeMillis();
        Object obj = pJoinPoint.proceed();
        System.out.println("Total milli seconds in execution of method: " + pJoinPoint.getSignature().getName() + " is :" + (System.currentTimeMillis()-startTime));
        return obj;




        And then wherever you use the annotation @TimeTracker total time will be printed, you can changes from sysout to logging



        For details, I have also pushed my sample code into github, have a look into that at: https://github.com/krishnaiitd/learningJava/tree/master/springBoot/gs-spring-boot/src/main/java/com/example/demo







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 14 at 17:17









        krishna Prasadkrishna Prasad

        1,3921 gold badge14 silver badges24 bronze badges




        1,3921 gold badge14 silver badges24 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55379917%2fpointcut-not-working-on-methods-with-arguments%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript