Java Spring注释:在@Repository或@Service原型的控制器原型中是否使用了类似于@ExceptionHandler的注释?
出于好奇,我试着看看是否可以在存储库中使用。正如预期的那样,注释被忽略 我有一个低优先级的检测服务,我不希望异常从中冒出来。与其用try/catch对instrumentation服务上的每个方法进行编码,我更希望该服务有一个Java Spring注释:在@Repository或@Service原型的控制器原型中是否使用了类似于@ExceptionHandler的注释?,java,spring,jakarta-ee,spring-mvc,Java,Spring,Jakarta Ee,Spring Mvc,出于好奇,我试着看看是否可以在存储库中使用。正如预期的那样,注释被忽略 我有一个低优先级的检测服务,我不希望异常从中冒出来。与其用try/catch对instrumentation服务上的每个方法进行编码,我更希望该服务有一个@ExceptionHandler方法-类似于Spring@Controller中使用的技术问题 想法?我不认为您现在就可以从Spring获得此功能(也许您想提出一个功能请求…),但您应该能够非常轻松地使用 @Aspect public class DaoAspect {
@ExceptionHandler
方法-类似于Spring@Controller
中使用的技术问题
想法?我不认为您现在就可以从Spring获得此功能(也许您想提出一个功能请求…),但您应该能够非常轻松地使用
@Aspect
public class DaoAspect {
@AfterThrowing(/*any method in a @Repository class that is not annotated with @ExceptionHandler*/ throwing="ex")
public void doRecoveryActions(DataAccessException ex) {
//find method of throwing class that can handle the exception via @ExceptionHandler
}
}