将@AfterThrowing与@ExceptionHandler一起使用

时间:2018-11-19 09:34:02

标签: 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++++++++++++++++");
    }
}

服务界面

public interface SignInService {
    CustomerSignInDTO signIn()
        throws LappException;
}    

服务实现类

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
    }
}

问题- 春季启动1.2.5

永远不会调用方法doRecoveryActions。我还在某处使用@ExceptionHandler来准备错误响应。是因为@ExceptionHandler捕获了所有异常并且从未调用doRecoveryActions吗?任何建议将不胜感激!

0 个答案:

没有答案