
要使其工作,您需要
throwExceptionIfNoHandlerFound在DispecherServlet 上设置属性。您可以执行以下 *** 作:
spring.mvc.throwExceptionIfNoHandlerFound=true
在
application.properties文件中,否则请求将始终转发到默认servlet,并且将引发NoHandlerFoundException。
问题是,即使使用此配置,它也不起作用。从文档中:
请注意,如果使用org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler,则请求将始终转发到默认servlet,并且在这种情况下永远不会引发NoHandlerFoundException。
由于默认情况下Spring
Boot使用,因此
org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler您必须使用自己的方法覆盖它
WebMvcConfigurer:
import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;import org.springframework.web.servlet.config.annotation.EnableWebMvc;import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@EnableWebMvc@Configurationpublic class WebConfig implements WebMvcConfigurer { @Override public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { // Do nothing instead of configurer.enable(); }}当然,上述情况在您的情况下可能会更复杂。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)