Spring Boot | Cloud 的全局异常——@ControllerAdvice注解不起作用

@ControllerAdvice的使用可参考:SpringBoot RESTful 应用中的异常处理小结

失效解决方法:在@SpringBootApplication后面加上(scanBasePackages=”your package path to ‘@ControllerAdvice’ class”)

  • E.G:
@SpringBootApplication(scanBasePackages="io.github.wesleysugarfree.tmcloud")
    ......
public class UserProviderApplication {
    public static void main(String[] args) {
         SpringApplication.run(UserProviderApplication.class, args);
    }
}

你可能感兴趣的:(Spring,Java)