Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring注释:在@Repository或@Service原型的控制器原型中是否使用了类似于@ExceptionHandler的注释?_Java_Spring_Jakarta Ee_Spring Mvc - Fatal编程技术网

Java Spring注释:在@Repository或@Service原型的控制器原型中是否使用了类似于@ExceptionHandler的注释?

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 {

出于好奇,我试着看看是否可以在存储库中使用。正如预期的那样,注释被忽略

我有一个低优先级的检测服务,我不希望异常从中冒出来。与其用try/catch对instrumentation服务上的每个方法进行编码,我更希望该服务有一个
@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
    }
}