Using @AfterThrowing with @ExceptionHandler
up vote
3
down vote
favorite
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
@Aspect
public class ExceptionAlerts {
public ExceptionAlerts() {
System.err.println("Class Scanned");
}
@AfterThrowing(pointcut = "com.name.papp.star", throwing = "ex")
public void doRecoveryAction(Throwable ex) throws Throwable {
System.err.println(">>>>>>>>>>>>>>>>Recovery Actions++++++++++++++++");
}
}
Service Interface
public interface SignInService {
CustomerSignInDTO signIn()
throws LappException;
}
Service Implementation Class
public class SignInServiceImpl implements SignInService {
@Override
@Transactional(readOnly = false, rollbackFor = Exception.class)
public CustomerSignInDTO signInCustomer(CustomerDeviceDTO customerDeviceDTO,
String mobileNumber, boolean createIfNotExist)
throws LappException {
// Throwing Exception Here
}
}
Problem -
Spring-Boot-1.2.5
The method doRecoveryActions
never gets called. I am also using @ExceptionHandler
somewhere to prepare the error response. Is it because @ExceptionHandler
catches all the exceptions and doRecoveryActions
is never called? Any suggestions would be appreciated!
java spring-aop
add a comment |
up vote
3
down vote
favorite
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
@Aspect
public class ExceptionAlerts {
public ExceptionAlerts() {
System.err.println("Class Scanned");
}
@AfterThrowing(pointcut = "com.name.papp.star", throwing = "ex")
public void doRecoveryAction(Throwable ex) throws Throwable {
System.err.println(">>>>>>>>>>>>>>>>Recovery Actions++++++++++++++++");
}
}
Service Interface
public interface SignInService {
CustomerSignInDTO signIn()
throws LappException;
}
Service Implementation Class
public class SignInServiceImpl implements SignInService {
@Override
@Transactional(readOnly = false, rollbackFor = Exception.class)
public CustomerSignInDTO signInCustomer(CustomerDeviceDTO customerDeviceDTO,
String mobileNumber, boolean createIfNotExist)
throws LappException {
// Throwing Exception Here
}
}
Problem -
Spring-Boot-1.2.5
The method doRecoveryActions
never gets called. I am also using @ExceptionHandler
somewhere to prepare the error response. Is it because @ExceptionHandler
catches all the exceptions and doRecoveryActions
is never called? Any suggestions would be appreciated!
java spring-aop
Does it work if you change signature to doRecoveryAction(Throwable ex)?
– Ermintar
Nov 19 at 9:40
No it doesn't. Tried that as well.
– kashish verma
Nov 19 at 9:43
Pls, post the real pointcut & executed method signature. @ExceptionHandler doesn't spoil AOP handlers
– Ermintar
Nov 19 at 9:46
Trouble is with your pointcut expression. Try pointcut = "execution(* com.name.papp.star.*)" to scan full package or "execution(* com.name.papp.star.auth.service.impl.signInCustomer(..))" for exact method
– Ermintar
Nov 19 at 10:20
Around("execution(* com..*ServiceImpl.*(..))") works perfectly with Around , but gives error when I use AfterThrowing. Could you please suggest an alternate, I have to give package based restrictions.
– kashish verma
Nov 19 at 12:52
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
@Aspect
public class ExceptionAlerts {
public ExceptionAlerts() {
System.err.println("Class Scanned");
}
@AfterThrowing(pointcut = "com.name.papp.star", throwing = "ex")
public void doRecoveryAction(Throwable ex) throws Throwable {
System.err.println(">>>>>>>>>>>>>>>>Recovery Actions++++++++++++++++");
}
}
Service Interface
public interface SignInService {
CustomerSignInDTO signIn()
throws LappException;
}
Service Implementation Class
public class SignInServiceImpl implements SignInService {
@Override
@Transactional(readOnly = false, rollbackFor = Exception.class)
public CustomerSignInDTO signInCustomer(CustomerDeviceDTO customerDeviceDTO,
String mobileNumber, boolean createIfNotExist)
throws LappException {
// Throwing Exception Here
}
}
Problem -
Spring-Boot-1.2.5
The method doRecoveryActions
never gets called. I am also using @ExceptionHandler
somewhere to prepare the error response. Is it because @ExceptionHandler
catches all the exceptions and doRecoveryActions
is never called? Any suggestions would be appreciated!
java spring-aop
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
@Aspect
public class ExceptionAlerts {
public ExceptionAlerts() {
System.err.println("Class Scanned");
}
@AfterThrowing(pointcut = "com.name.papp.star", throwing = "ex")
public void doRecoveryAction(Throwable ex) throws Throwable {
System.err.println(">>>>>>>>>>>>>>>>Recovery Actions++++++++++++++++");
}
}
Service Interface
public interface SignInService {
CustomerSignInDTO signIn()
throws LappException;
}
Service Implementation Class
public class SignInServiceImpl implements SignInService {
@Override
@Transactional(readOnly = false, rollbackFor = Exception.class)
public CustomerSignInDTO signInCustomer(CustomerDeviceDTO customerDeviceDTO,
String mobileNumber, boolean createIfNotExist)
throws LappException {
// Throwing Exception Here
}
}
Problem -
Spring-Boot-1.2.5
The method doRecoveryActions
never gets called. I am also using @ExceptionHandler
somewhere to prepare the error response. Is it because @ExceptionHandler
catches all the exceptions and doRecoveryActions
is never called? Any suggestions would be appreciated!
java spring-aop
java spring-aop
edited yesterday
pushkin
3,738102450
3,738102450
asked Nov 19 at 9:34
kashish verma
664
664
Does it work if you change signature to doRecoveryAction(Throwable ex)?
– Ermintar
Nov 19 at 9:40
No it doesn't. Tried that as well.
– kashish verma
Nov 19 at 9:43
Pls, post the real pointcut & executed method signature. @ExceptionHandler doesn't spoil AOP handlers
– Ermintar
Nov 19 at 9:46
Trouble is with your pointcut expression. Try pointcut = "execution(* com.name.papp.star.*)" to scan full package or "execution(* com.name.papp.star.auth.service.impl.signInCustomer(..))" for exact method
– Ermintar
Nov 19 at 10:20
Around("execution(* com..*ServiceImpl.*(..))") works perfectly with Around , but gives error when I use AfterThrowing. Could you please suggest an alternate, I have to give package based restrictions.
– kashish verma
Nov 19 at 12:52
add a comment |
Does it work if you change signature to doRecoveryAction(Throwable ex)?
– Ermintar
Nov 19 at 9:40
No it doesn't. Tried that as well.
– kashish verma
Nov 19 at 9:43
Pls, post the real pointcut & executed method signature. @ExceptionHandler doesn't spoil AOP handlers
– Ermintar
Nov 19 at 9:46
Trouble is with your pointcut expression. Try pointcut = "execution(* com.name.papp.star.*)" to scan full package or "execution(* com.name.papp.star.auth.service.impl.signInCustomer(..))" for exact method
– Ermintar
Nov 19 at 10:20
Around("execution(* com..*ServiceImpl.*(..))") works perfectly with Around , but gives error when I use AfterThrowing. Could you please suggest an alternate, I have to give package based restrictions.
– kashish verma
Nov 19 at 12:52
Does it work if you change signature to doRecoveryAction(Throwable ex)?
– Ermintar
Nov 19 at 9:40
Does it work if you change signature to doRecoveryAction(Throwable ex)?
– Ermintar
Nov 19 at 9:40
No it doesn't. Tried that as well.
– kashish verma
Nov 19 at 9:43
No it doesn't. Tried that as well.
– kashish verma
Nov 19 at 9:43
Pls, post the real pointcut & executed method signature. @ExceptionHandler doesn't spoil AOP handlers
– Ermintar
Nov 19 at 9:46
Pls, post the real pointcut & executed method signature. @ExceptionHandler doesn't spoil AOP handlers
– Ermintar
Nov 19 at 9:46
Trouble is with your pointcut expression. Try pointcut = "execution(* com.name.papp.star.*)" to scan full package or "execution(* com.name.papp.star.auth.service.impl.signInCustomer(..))" for exact method
– Ermintar
Nov 19 at 10:20
Trouble is with your pointcut expression. Try pointcut = "execution(* com.name.papp.star.*)" to scan full package or "execution(* com.name.papp.star.auth.service.impl.signInCustomer(..))" for exact method
– Ermintar
Nov 19 at 10:20
Around("execution(* com..*ServiceImpl.*(..))") works perfectly with Around , but gives error when I use AfterThrowing. Could you please suggest an alternate, I have to give package based restrictions.
– kashish verma
Nov 19 at 12:52
Around("execution(* com..*ServiceImpl.*(..))") works perfectly with Around , but gives error when I use AfterThrowing. Could you please suggest an alternate, I have to give package based restrictions.
– kashish verma
Nov 19 at 12:52
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53371744%2fusing-afterthrowing-with-exceptionhandler%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
Does it work if you change signature to doRecoveryAction(Throwable ex)?
– Ermintar
Nov 19 at 9:40
No it doesn't. Tried that as well.
– kashish verma
Nov 19 at 9:43
Pls, post the real pointcut & executed method signature. @ExceptionHandler doesn't spoil AOP handlers
– Ermintar
Nov 19 at 9:46
Trouble is with your pointcut expression. Try pointcut = "execution(* com.name.papp.star.*)" to scan full package or "execution(* com.name.papp.star.auth.service.impl.signInCustomer(..))" for exact method
– Ermintar
Nov 19 at 10:20
Around("execution(* com..*ServiceImpl.*(..))") works perfectly with Around , but gives error when I use AfterThrowing. Could you please suggest an alternate, I have to give package based restrictions.
– kashish verma
Nov 19 at 12:52