Spring AOP Aspect advice with method parameters The Next CEO of Stack OverflowSpring - @Transactional - What happens in background?Why does my Spring AOP aspect work in my unit test but not my webapp?Spring AOP Aspect not executingWhat's the difference between @Component, @Repository & @Service annotations in Spring?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?AspectJ aspect is not being intercepted if @Cacheble Spring AOP applied on the same functionAOP Spring @AfterReturning not working as expectedHow exactly does an @Around advice work in Spring AOP?Spring AOP: How to read path variable value from URI template in aspect?Spring AOP pointcut by declared return type

Is there a way to save my career from absolute disaster?

A Man With a Stainless Steel Endoskeleton (like The Terminator) Fighting Cloaked Aliens Only He Can See

Can we say or write : "No, it'sn't"?

Can a Bladesinger Wizard use Bladesong with a Hand Crossbow?

Why did CATV standarize in 75 ohms and everyone else in 50?

Won the lottery - how do I keep the money?

Is it okay to majorly distort historical facts while writing a fiction story?

What flight has the highest ratio of time difference to flight time?

Are police here, aren't itthey?

Why does the flight controls check come before arming the autobrake on the A320?

Plot of histogram similar to output from @risk

How to scale a tikZ image which is within a figure environment

Is it my responsibility to learn a new technology in my own time my employer wants to implement?

INSERT to a table from a database to other (same SQL Server) using Dynamic SQL

How many extra stops do monopods offer for tele photographs?

Proper way to express "He disappeared them"

The exact meaning of 'Mom made me a sandwich'

Why is quantifier elimination desirable for a given theory?

How to place nodes around a circle from some initial angle?

Does increasing your ability score affect your main stat?

How do I align (1) and (2)?

Why isn't acceleration always zero whenever velocity is zero, such as the moment a ball bounces off a wall?

Why is my new battery behaving weirdly?

Why doesn't UK go for the same deal Japan has with EU to resolve Brexit?



Spring AOP Aspect advice with method parameters



The Next CEO of Stack OverflowSpring - @Transactional - What happens in background?Why does my Spring AOP aspect work in my unit test but not my webapp?Spring AOP Aspect not executingWhat's the difference between @Component, @Repository & @Service annotations in Spring?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?AspectJ aspect is not being intercepted if @Cacheble Spring AOP applied on the same functionAOP Spring @AfterReturning not working as expectedHow exactly does an @Around advice work in Spring AOP?Spring AOP: How to read path variable value from URI template in aspect?Spring AOP pointcut by declared return type










1















I have an aspect advice like following



@AfterReturning("execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..))")
public void fixUrl()
....


getAttribute method accepts only one String parameter.



what I would like to do, I want "fixUrl" to be executed only when 'name' string is given as parameter. "getAttribute('name')". How can I do that? Thanks!










share|improve this question


























    1















    I have an aspect advice like following



    @AfterReturning("execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..))")
    public void fixUrl()
    ....


    getAttribute method accepts only one String parameter.



    what I would like to do, I want "fixUrl" to be executed only when 'name' string is given as parameter. "getAttribute('name')". How can I do that? Thanks!










    share|improve this question
























      1












      1








      1


      2






      I have an aspect advice like following



      @AfterReturning("execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..))")
      public void fixUrl()
      ....


      getAttribute method accepts only one String parameter.



      what I would like to do, I want "fixUrl" to be executed only when 'name' string is given as parameter. "getAttribute('name')". How can I do that? Thanks!










      share|improve this question














      I have an aspect advice like following



      @AfterReturning("execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..))")
      public void fixUrl()
      ....


      getAttribute method accepts only one String parameter.



      what I would like to do, I want "fixUrl" to be executed only when 'name' string is given as parameter. "getAttribute('name')". How can I do that? Thanks!







      spring spring-mvc aop aspectj spring-aop






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 21 at 18:08









      EsatEsat

      462




      462






















          3 Answers
          3






          active

          oldest

          votes


















          0














          @AfterReturning(value = "execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..)) && args(String)")
          public void after1(JoinPoint jp)
          System.out.println(jp.getArgs()[0]);
          System.out.println("after Return:"+jp.getSignature());



          Above Way Can work. If you want support other type except String ,change String to what you want . jp.getArgs()[0] get the variable!
          The below Way you can try , i try it successfully in my code!



           @AfterReturning(value = "execution(@AfterReturning(value = "execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..)) && args(a)")
          public void after2(JoinPoint jp,String a)
          System.out.println(a);
          System.out.println("after Return:"+jp.getSignature());






          share|improve this answer























          • Thanks for your reply, I am looking for something inside annotation to give method value. I mean, I don't want to if/else inside method body. Method will be executed only if this specific has been passed.

            – Esat
            Mar 22 at 10:34


















          0














          What you're asking isn't possible. Method pointcut expressions are powerful in distinguishing which methods to join or exclude, based on signature and context. The values of the arguments themselves are outside that scope.



          In any case, I'd argue there's an advantage to putting the conditional check in your code. It's more resistant to breakage from refactoring, particularly if you make the value you're checking for a constant.






          share|improve this answer






























            0














            Here is your aspect code:



            @AfterReturning("execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..))")
            public void fixUrl(JoinPoint p)
            String name;
            Object[] signatureArgs = p.getArgs();
            if (signatureArgs.length > 0) InvocationTargetException e)
            e.printStackTrace();





            Here name has value that is provided. If null then not provided. I added the
            log, is there name has or not.



            Here is your imports:



            import org.aspectj.lang.JoinPoint;

            import java.lang.reflect.InvocationTargetException;
            import java.lang.reflect.Method;
            import java.util.concurrent.ExecutionException;





            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%2f55286712%2fspring-aop-aspect-advice-with-method-parameters%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              @AfterReturning(value = "execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..)) && args(String)")
              public void after1(JoinPoint jp)
              System.out.println(jp.getArgs()[0]);
              System.out.println("after Return:"+jp.getSignature());



              Above Way Can work. If you want support other type except String ,change String to what you want . jp.getArgs()[0] get the variable!
              The below Way you can try , i try it successfully in my code!



               @AfterReturning(value = "execution(@AfterReturning(value = "execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..)) && args(a)")
              public void after2(JoinPoint jp,String a)
              System.out.println(a);
              System.out.println("after Return:"+jp.getSignature());






              share|improve this answer























              • Thanks for your reply, I am looking for something inside annotation to give method value. I mean, I don't want to if/else inside method body. Method will be executed only if this specific has been passed.

                – Esat
                Mar 22 at 10:34















              0














              @AfterReturning(value = "execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..)) && args(String)")
              public void after1(JoinPoint jp)
              System.out.println(jp.getArgs()[0]);
              System.out.println("after Return:"+jp.getSignature());



              Above Way Can work. If you want support other type except String ,change String to what you want . jp.getArgs()[0] get the variable!
              The below Way you can try , i try it successfully in my code!



               @AfterReturning(value = "execution(@AfterReturning(value = "execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..)) && args(a)")
              public void after2(JoinPoint jp,String a)
              System.out.println(a);
              System.out.println("after Return:"+jp.getSignature());






              share|improve this answer























              • Thanks for your reply, I am looking for something inside annotation to give method value. I mean, I don't want to if/else inside method body. Method will be executed only if this specific has been passed.

                – Esat
                Mar 22 at 10:34













              0












              0








              0







              @AfterReturning(value = "execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..)) && args(String)")
              public void after1(JoinPoint jp)
              System.out.println(jp.getArgs()[0]);
              System.out.println("after Return:"+jp.getSignature());



              Above Way Can work. If you want support other type except String ,change String to what you want . jp.getArgs()[0] get the variable!
              The below Way you can try , i try it successfully in my code!



               @AfterReturning(value = "execution(@AfterReturning(value = "execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..)) && args(a)")
              public void after2(JoinPoint jp,String a)
              System.out.println(a);
              System.out.println("after Return:"+jp.getSignature());






              share|improve this answer













              @AfterReturning(value = "execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..)) && args(String)")
              public void after1(JoinPoint jp)
              System.out.println(jp.getArgs()[0]);
              System.out.println("after Return:"+jp.getSignature());



              Above Way Can work. If you want support other type except String ,change String to what you want . jp.getArgs()[0] get the variable!
              The below Way you can try , i try it successfully in my code!



               @AfterReturning(value = "execution(@AfterReturning(value = "execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..)) && args(a)")
              public void after2(JoinPoint jp,String a)
              System.out.println(a);
              System.out.println("after Return:"+jp.getSignature());







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 22 at 8:26









              lvbinbin2luolilvbinbin2luoli

              91




              91












              • Thanks for your reply, I am looking for something inside annotation to give method value. I mean, I don't want to if/else inside method body. Method will be executed only if this specific has been passed.

                – Esat
                Mar 22 at 10:34

















              • Thanks for your reply, I am looking for something inside annotation to give method value. I mean, I don't want to if/else inside method body. Method will be executed only if this specific has been passed.

                – Esat
                Mar 22 at 10:34
















              Thanks for your reply, I am looking for something inside annotation to give method value. I mean, I don't want to if/else inside method body. Method will be executed only if this specific has been passed.

              – Esat
              Mar 22 at 10:34





              Thanks for your reply, I am looking for something inside annotation to give method value. I mean, I don't want to if/else inside method body. Method will be executed only if this specific has been passed.

              – Esat
              Mar 22 at 10:34













              0














              What you're asking isn't possible. Method pointcut expressions are powerful in distinguishing which methods to join or exclude, based on signature and context. The values of the arguments themselves are outside that scope.



              In any case, I'd argue there's an advantage to putting the conditional check in your code. It's more resistant to breakage from refactoring, particularly if you make the value you're checking for a constant.






              share|improve this answer



























                0














                What you're asking isn't possible. Method pointcut expressions are powerful in distinguishing which methods to join or exclude, based on signature and context. The values of the arguments themselves are outside that scope.



                In any case, I'd argue there's an advantage to putting the conditional check in your code. It's more resistant to breakage from refactoring, particularly if you make the value you're checking for a constant.






                share|improve this answer

























                  0












                  0








                  0







                  What you're asking isn't possible. Method pointcut expressions are powerful in distinguishing which methods to join or exclude, based on signature and context. The values of the arguments themselves are outside that scope.



                  In any case, I'd argue there's an advantage to putting the conditional check in your code. It's more resistant to breakage from refactoring, particularly if you make the value you're checking for a constant.






                  share|improve this answer













                  What you're asking isn't possible. Method pointcut expressions are powerful in distinguishing which methods to join or exclude, based on signature and context. The values of the arguments themselves are outside that scope.



                  In any case, I'd argue there's an advantage to putting the conditional check in your code. It's more resistant to breakage from refactoring, particularly if you make the value you're checking for a constant.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 25 at 0:14









                  David SiegalDavid Siegal

                  4,018298




                  4,018298





















                      0














                      Here is your aspect code:



                      @AfterReturning("execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..))")
                      public void fixUrl(JoinPoint p)
                      String name;
                      Object[] signatureArgs = p.getArgs();
                      if (signatureArgs.length > 0) InvocationTargetException e)
                      e.printStackTrace();





                      Here name has value that is provided. If null then not provided. I added the
                      log, is there name has or not.



                      Here is your imports:



                      import org.aspectj.lang.JoinPoint;

                      import java.lang.reflect.InvocationTargetException;
                      import java.lang.reflect.Method;
                      import java.util.concurrent.ExecutionException;





                      share|improve this answer



























                        0














                        Here is your aspect code:



                        @AfterReturning("execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..))")
                        public void fixUrl(JoinPoint p)
                        String name;
                        Object[] signatureArgs = p.getArgs();
                        if (signatureArgs.length > 0) InvocationTargetException e)
                        e.printStackTrace();





                        Here name has value that is provided. If null then not provided. I added the
                        log, is there name has or not.



                        Here is your imports:



                        import org.aspectj.lang.JoinPoint;

                        import java.lang.reflect.InvocationTargetException;
                        import java.lang.reflect.Method;
                        import java.util.concurrent.ExecutionException;





                        share|improve this answer

























                          0












                          0








                          0







                          Here is your aspect code:



                          @AfterReturning("execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..))")
                          public void fixUrl(JoinPoint p)
                          String name;
                          Object[] signatureArgs = p.getArgs();
                          if (signatureArgs.length > 0) InvocationTargetException e)
                          e.printStackTrace();





                          Here name has value that is provided. If null then not provided. I added the
                          log, is there name has or not.



                          Here is your imports:



                          import org.aspectj.lang.JoinPoint;

                          import java.lang.reflect.InvocationTargetException;
                          import java.lang.reflect.Method;
                          import java.util.concurrent.ExecutionException;





                          share|improve this answer













                          Here is your aspect code:



                          @AfterReturning("execution(* de.ojk.platform.servicelayer.session.SessionService.getAttribute(..))")
                          public void fixUrl(JoinPoint p)
                          String name;
                          Object[] signatureArgs = p.getArgs();
                          if (signatureArgs.length > 0) InvocationTargetException e)
                          e.printStackTrace();





                          Here name has value that is provided. If null then not provided. I added the
                          log, is there name has or not.



                          Here is your imports:



                          import org.aspectj.lang.JoinPoint;

                          import java.lang.reflect.InvocationTargetException;
                          import java.lang.reflect.Method;
                          import java.util.concurrent.ExecutionException;






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 25 at 5:35









                          Md. Sajedul KarimMd. Sajedul Karim

                          3,3902755




                          3,3902755



























                              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%2f55286712%2fspring-aop-aspect-advice-with-method-parameters%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

                              SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                              용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                              155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해