简体   繁体   English

有什么方法可以在@Service上使用@ControllerAdvice

[英]Is there any way to use @ControllerAdvice on @Service

我有一个项目需求,我将没有任何@Controller@RestController但是我需要为我的服务层提供一个全局异常处理程序,因此我需要在@Service上配置@ControllerAdvice ,请告诉我是否有其他方法也可以做到这一点。

@ControllerAdvice is specifically relevant to Spring MVC controllers, so you can't use it on arbitrary beans. @ControllerAdvice与Spring MVC控制器特别相关,因此您不能在任意bean上使用它。 What you're probably looking for is the regular Spring AOP support using @Aspect . 您可能正在寻找的是使用@Aspect的常规Spring AOP支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我使用 @ControllerAdvice 填充 @ModelAttribute 是否会发生任何冲突 - Will I have any collisions coming from the @ControllerAdvice if I use it to populate a @ModelAttribute 如何使控制器使用特定的@ControllerAdvice而不是其他控制器? - How make a controller use a specific @ControllerAdvice and not another? @ControllerAdvice 注解的 class 没有捕捉到服务层抛出的异常 - @ControllerAdvice annotated class is not catching the exception thrown in the service layer 在服务上使用@Transactional的正确方法 - Proper way to use @Transactional on a service 在java中是否有任何方法可以使用AND代替&& - In java is there any way to use AND instead of && 有什么方法可以将SSLContext与ServerSocketChannel一起使用? - Is there any way to use SSLContext with ServerSocketChannel? spring-boot 中的 @ControllerAdvice 注释是什么,我们为什么以及何时使用它? - What is @ControllerAdvice annotation in spring-boot and why we use it and when? 有没有什么方法可以像消费者一样简单地使用BiConsumers? - Is there any way to use BiConsumers as simply as Consumers? 有没有办法在Jsoup中使用连接池? - Is there any way to use connection pool in Jsoup? 有没有其他方法可以使用实例变量? - Is there any way to use an instance variable in another method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM