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
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
add a comment |
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
add a comment |
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
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
spring spring-mvc aop aspectj spring-aop
asked Mar 21 at 18:08
EsatEsat
462
462
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
@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());
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
add a comment |
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.
add a comment |
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;
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
@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());
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
add a comment |
@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());
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
add a comment |
@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());
@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());
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 25 at 0:14
David SiegalDavid Siegal
4,018298
4,018298
add a comment |
add a comment |
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;
add a comment |
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;
add a comment |
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;
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;
answered Mar 25 at 5:35
Md. Sajedul KarimMd. Sajedul Karim
3,3902755
3,3902755
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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