没有处理程序在spring boot中发现异常和静态资源

问题描述 投票:7回答:2

我有一个Spring Boot Web应用程序,我在ControllerAdvice类中捕获我的自定义异常。问题是如果没有找到处理程序,Spring Boot默认不抛出异常(它将json发送回客户端)。

我想要的是在我的NoHandlerFoundException课程中捕捉ControllerAdvice。为了实现这一点,我明确配置了

spring.mvc.throw-exception-if-no-handler-found=true
spring.resources.add-mappings=false

这个技巧完成了工作,我现在可以捕获NoHandlerFoundException,但它禁用Spring来自动配置静态资源的路径。所以我的所有静态资源现在都不能用于客户端。我试图使用一个没有帮助的配置来解决这个问题

spring.resources.static-locations=classpath:/resources/static/

当使用Spring Boot禁用自动配置时,有人可以建议如何在spring.resources.add-mappings=false中映射静态资源吗?

谢谢!

java spring-boot
2个回答
© www.soinside.com 2019 - 2024. All rights reserved.