使用SpringBoot配置了 server.servlet.path后無效的解決方案


一、問題描述

  使用SpringBoot配置了 server.servlet.path后無效,訪問時無法通過:http://127.0.0.1:8080/app/hello.html 訪問。

二、解決方法一:

   

server:
  address: 0.0.0.0
  port: 8080
  tomcat:
    uri-encoding: utf-8
  servlet:
    context-path: "/app"
 path: "*.html" spring:
  servlet:
    multipart:
      max-request-size: 50Mb
      max-file-size: 50Mb
 mvc: pathmatch: use-suffix-pattern: true #啟用這個之后, server.servlet.path配置后綴才會生效。


constant:
  company: Yungoal
  address: 北京市上地九街數碼科技廣場

logging:
  level:
    root: error
    org.springframework.web: ERROR
    com.yungoal: debug

 

如圖:

  

  

 

三、解決方法二:

@Configuration
public class CustomwebMvcConfigurer implements WebMvcConfigurer {
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.setUseRegisteredSuffixPatternMatch(true);
    }
}
@Bean
    public ServletRegistrationBean servletRegistrationBean(DispatcherServlet dispatcherServlet) {
        ServletRegistrationBean<DispatcherServlet> servletServletRegistrationBean = new ServletRegistrationBean<>(dispatcherServlet);
        servletServletRegistrationBean.addUrlMappings(Arrays.asList("*.html"));
        return servletServletRegistrationBean;
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM