2023-06-21 16:07:18.705+0800 [] [main] WARN  org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: 
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource 
[org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; 
nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: 
Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: 
Unable to locate the default servlet for serving static content. Please set the 'defaultServletName' property explicitly.

主要来说就是这一段 Unable to locate the default servlet for serving static content. Please set the 'defaultServletName' property explicitly.

这是由于我升级了SpringBoot的版本,Servlet提供的DefaultServlet不自动注册,需要在 application.properties配置

server.servlet.register-default-servlet=true
最后修改:2023 年 06 月 21 日
如果觉得我的文章对你有用,请随意赞赏