why does my aspect code not run when exception is thrown?2019 Community Moderator ElectionHow do you assert that a certain exception is thrown in JUnit 4 tests?Why does Java have transient fields?Spring, Aspect J, multiple AfterThrowing advice applied to the same pointcutIntelliJ inspection gives “Cannot resolve symbol” but still compiles codeSpring Aspect not executed when defined in other JARWhy does this code using random strings print “hello world”?Why is executing Java code in comments with certain Unicode characters allowed?AspectJ and Spring: Exclude @After method execution when method throws an exceptionHow to log exception details in Spring AOP with try with empty catch block?java exception - why does it catch?
Does the in-code argument passing conventions used on PDP-11's have a name?
Why can't we use freedom of speech and expression to incite people to rebel against government in India?
Replacing tantalum capacitor with ceramic capacitor for Op Amps
What is "desert glass" and what does it do to the PCs?
Why are special aircraft used for the carriers in the United States Navy?
How do we objectively assess if a dialogue sounds unnatural or cringy?
Affine transformation of circular arc in 3D
Quitting employee has privileged access to critical information
What is Tony Stark injecting into himself in Iron Man 3?
Is being socially reclusive okay for a graduate student?
Called into a meeting and told we are being made redundant (laid off) and "not to share outside". Can I tell my partner?
School performs periodic password audits. Is my password compromised?
Paper published similar to PhD thesis
Has a sovereign Communist government ever run, and conceded loss, on a fair election?
Align equations with text before one of them
Is there a math expression equivalent to the conditional ternary operator?
Short story about an infectious indestructible metal bar?
Is there a frame of reference in which I was born before I was conceived?
Computing the volume of a simplex-like object with constraints
What's the best tool for cutting holes into duct work?
What is the meaning of option 'by' in TikZ Intersections
Why do phishing e-mails use faked e-mail addresses instead of the real one?
What is better: yes / no radio, or simple checkbox?
Naming Characters after Friends/Family
why does my aspect code not run when exception is thrown?
2019 Community Moderator ElectionHow do you assert that a certain exception is thrown in JUnit 4 tests?Why does Java have transient fields?Spring, Aspect J, multiple AfterThrowing advice applied to the same pointcutIntelliJ inspection gives “Cannot resolve symbol” but still compiles codeSpring Aspect not executed when defined in other JARWhy does this code using random strings print “hello world”?Why is executing Java code in comments with certain Unicode characters allowed?AspectJ and Spring: Exclude @After method execution when method throws an exceptionHow to log exception details in Spring AOP with try with empty catch block?java exception - why does it catch?
In my spring
project I've added two dependencies:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.2</version>
</dependency>
and then I've created a class:
package com.my.company.package.handling;
@Aspect
public class MyAspect
@AfterThrowing(pointcut = "execution(* com.my.company.package.*(..))", throwing = "ex")
public void logAfterThrowing(Exception ex)
System.out.println("exception "+ex.getLocalizedMessage())
Now in some other class (stored in package: com.my.company.package.someOtherPackage
) I'm throwing exception:
throw new IOException("here comes error");
but then I don't see the printout from my aspect method in the console. What am I missing here?
java spring aspectj
add a comment |
In my spring
project I've added two dependencies:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.2</version>
</dependency>
and then I've created a class:
package com.my.company.package.handling;
@Aspect
public class MyAspect
@AfterThrowing(pointcut = "execution(* com.my.company.package.*(..))", throwing = "ex")
public void logAfterThrowing(Exception ex)
System.out.println("exception "+ex.getLocalizedMessage())
Now in some other class (stored in package: com.my.company.package.someOtherPackage
) I'm throwing exception:
throw new IOException("here comes error");
but then I don't see the printout from my aspect method in the console. What am I missing here?
java spring aspectj
1
isn't there missing a.*
for the method name? I don't use AspectJ but documentation states: "execution of any method defined in the service package:execution(* com.xyz.service.*.*(..))
" (assuming that yoursomeOtherPackage
is a class), or: " execution of any method defined in the service package or a sub-package:execution(* com.xyz.service..*.*(..))
"
– Carlos Heuberger
yesterday
@CarlosHeuberger just realised the same thing, I've updated my answer.
– Essex Boy
yesterday
add a comment |
In my spring
project I've added two dependencies:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.2</version>
</dependency>
and then I've created a class:
package com.my.company.package.handling;
@Aspect
public class MyAspect
@AfterThrowing(pointcut = "execution(* com.my.company.package.*(..))", throwing = "ex")
public void logAfterThrowing(Exception ex)
System.out.println("exception "+ex.getLocalizedMessage())
Now in some other class (stored in package: com.my.company.package.someOtherPackage
) I'm throwing exception:
throw new IOException("here comes error");
but then I don't see the printout from my aspect method in the console. What am I missing here?
java spring aspectj
In my spring
project I've added two dependencies:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.2</version>
</dependency>
and then I've created a class:
package com.my.company.package.handling;
@Aspect
public class MyAspect
@AfterThrowing(pointcut = "execution(* com.my.company.package.*(..))", throwing = "ex")
public void logAfterThrowing(Exception ex)
System.out.println("exception "+ex.getLocalizedMessage())
Now in some other class (stored in package: com.my.company.package.someOtherPackage
) I'm throwing exception:
throw new IOException("here comes error");
but then I don't see the printout from my aspect method in the console. What am I missing here?
java spring aspectj
java spring aspectj
asked yesterday
randomuser1randomuser1
1,07431539
1,07431539
1
isn't there missing a.*
for the method name? I don't use AspectJ but documentation states: "execution of any method defined in the service package:execution(* com.xyz.service.*.*(..))
" (assuming that yoursomeOtherPackage
is a class), or: " execution of any method defined in the service package or a sub-package:execution(* com.xyz.service..*.*(..))
"
– Carlos Heuberger
yesterday
@CarlosHeuberger just realised the same thing, I've updated my answer.
– Essex Boy
yesterday
add a comment |
1
isn't there missing a.*
for the method name? I don't use AspectJ but documentation states: "execution of any method defined in the service package:execution(* com.xyz.service.*.*(..))
" (assuming that yoursomeOtherPackage
is a class), or: " execution of any method defined in the service package or a sub-package:execution(* com.xyz.service..*.*(..))
"
– Carlos Heuberger
yesterday
@CarlosHeuberger just realised the same thing, I've updated my answer.
– Essex Boy
yesterday
1
1
isn't there missing a
.*
for the method name? I don't use AspectJ but documentation states: "execution of any method defined in the service package: execution(* com.xyz.service.*.*(..))
" (assuming that your someOtherPackage
is a class), or: " execution of any method defined in the service package or a sub-package: execution(* com.xyz.service..*.*(..))
"– Carlos Heuberger
yesterday
isn't there missing a
.*
for the method name? I don't use AspectJ but documentation states: "execution of any method defined in the service package: execution(* com.xyz.service.*.*(..))
" (assuming that your someOtherPackage
is a class), or: " execution of any method defined in the service package or a sub-package: execution(* com.xyz.service..*.*(..))
"– Carlos Heuberger
yesterday
@CarlosHeuberger just realised the same thing, I've updated my answer.
– Essex Boy
yesterday
@CarlosHeuberger just realised the same thing, I've updated my answer.
– Essex Boy
yesterday
add a comment |
1 Answer
1
active
oldest
votes
Assuming everything else is correct you need a @Component annotation also, you also need another * in the execution string for any class.
@Aspect
@Component
public class MyAspect
@AfterThrowing(pointcut = "execution(* com.my.company.package.*.*(..))", throwing = "ex")
public void logAfterThrowing(Exception ex)
System.out.println("exception "+ex.getLocalizedMessage())
Here's a working example
Thanks, however when I used it - I'm not seeing the message fromlogAfterThrowing
. I tried to invoke it in my code by throwing e.g.throw new ParseException("msg", 0)
orthrow new NullPointerException("msg");
but message from Aspect does not show up
– randomuser1
yesterday
@randomuser1 it works for me in the test, something else wrong?
– Essex Boy
yesterday
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%2f55023224%2fwhy-does-my-aspect-code-not-run-when-exception-is-thrown%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
Assuming everything else is correct you need a @Component annotation also, you also need another * in the execution string for any class.
@Aspect
@Component
public class MyAspect
@AfterThrowing(pointcut = "execution(* com.my.company.package.*.*(..))", throwing = "ex")
public void logAfterThrowing(Exception ex)
System.out.println("exception "+ex.getLocalizedMessage())
Here's a working example
Thanks, however when I used it - I'm not seeing the message fromlogAfterThrowing
. I tried to invoke it in my code by throwing e.g.throw new ParseException("msg", 0)
orthrow new NullPointerException("msg");
but message from Aspect does not show up
– randomuser1
yesterday
@randomuser1 it works for me in the test, something else wrong?
– Essex Boy
yesterday
add a comment |
Assuming everything else is correct you need a @Component annotation also, you also need another * in the execution string for any class.
@Aspect
@Component
public class MyAspect
@AfterThrowing(pointcut = "execution(* com.my.company.package.*.*(..))", throwing = "ex")
public void logAfterThrowing(Exception ex)
System.out.println("exception "+ex.getLocalizedMessage())
Here's a working example
Thanks, however when I used it - I'm not seeing the message fromlogAfterThrowing
. I tried to invoke it in my code by throwing e.g.throw new ParseException("msg", 0)
orthrow new NullPointerException("msg");
but message from Aspect does not show up
– randomuser1
yesterday
@randomuser1 it works for me in the test, something else wrong?
– Essex Boy
yesterday
add a comment |
Assuming everything else is correct you need a @Component annotation also, you also need another * in the execution string for any class.
@Aspect
@Component
public class MyAspect
@AfterThrowing(pointcut = "execution(* com.my.company.package.*.*(..))", throwing = "ex")
public void logAfterThrowing(Exception ex)
System.out.println("exception "+ex.getLocalizedMessage())
Here's a working example
Assuming everything else is correct you need a @Component annotation also, you also need another * in the execution string for any class.
@Aspect
@Component
public class MyAspect
@AfterThrowing(pointcut = "execution(* com.my.company.package.*.*(..))", throwing = "ex")
public void logAfterThrowing(Exception ex)
System.out.println("exception "+ex.getLocalizedMessage())
Here's a working example
edited yesterday
answered yesterday
Essex BoyEssex Boy
4,6781816
4,6781816
Thanks, however when I used it - I'm not seeing the message fromlogAfterThrowing
. I tried to invoke it in my code by throwing e.g.throw new ParseException("msg", 0)
orthrow new NullPointerException("msg");
but message from Aspect does not show up
– randomuser1
yesterday
@randomuser1 it works for me in the test, something else wrong?
– Essex Boy
yesterday
add a comment |
Thanks, however when I used it - I'm not seeing the message fromlogAfterThrowing
. I tried to invoke it in my code by throwing e.g.throw new ParseException("msg", 0)
orthrow new NullPointerException("msg");
but message from Aspect does not show up
– randomuser1
yesterday
@randomuser1 it works for me in the test, something else wrong?
– Essex Boy
yesterday
Thanks, however when I used it - I'm not seeing the message from
logAfterThrowing
. I tried to invoke it in my code by throwing e.g. throw new ParseException("msg", 0)
or throw new NullPointerException("msg");
but message from Aspect does not show up– randomuser1
yesterday
Thanks, however when I used it - I'm not seeing the message from
logAfterThrowing
. I tried to invoke it in my code by throwing e.g. throw new ParseException("msg", 0)
or throw new NullPointerException("msg");
but message from Aspect does not show up– randomuser1
yesterday
@randomuser1 it works for me in the test, something else wrong?
– Essex Boy
yesterday
@randomuser1 it works for me in the test, something else wrong?
– Essex Boy
yesterday
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%2f55023224%2fwhy-does-my-aspect-code-not-run-when-exception-is-thrown%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
1
isn't there missing a
.*
for the method name? I don't use AspectJ but documentation states: "execution of any method defined in the service package:execution(* com.xyz.service.*.*(..))
" (assuming that yoursomeOtherPackage
is a class), or: " execution of any method defined in the service package or a sub-package:execution(* com.xyz.service..*.*(..))
"– Carlos Heuberger
yesterday
@CarlosHeuberger just realised the same thing, I've updated my answer.
– Essex Boy
yesterday