【问题标题】:Spring annotations: Is there a similar annotation like @ExceptionHandler used in Controller stereotypes for @Repository or @Service stereotypes?Spring注解:在@Repository 或@Service 原型的控制器原型中是否有类似@ExceptionHandler 的注释?
【发布时间】:2012-02-24 19:48:12
【问题描述】:
【问题讨论】:
标签:
java
spring
jakarta-ee
spring-mvc
【解决方案1】:
我认为您现在无法从 Spring 获得此功能(也许您想提出功能请求...),但您应该可以使用 Spring AOP 轻松完成此操作。
@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
}
}