修复https://github.com/spring-projects/spring-boot/issues/12934和https://github.com/spring-projects/spring-boot/issues/13106所做的更改意味着像这样的应用程序:
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.DispatcherServlet;
@SpringBootApplication
public class CustomDispatcherServletApplication {
public static void main(String[] args) {
SpringApplication.run(CustomDispatcherServletApplication.class, args);
}
@Bean
public DispatcherServlet dispatcherServlet() {
return new DispatcherServlet();
}
}
会因为这样的失败而无法启动:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.3.RELEASE)
2018-06-19 20:20:20.305 INFO 8473 --- [ main] c.e.d.CustomDispatcherServletApplication : Starting CustomDispatcherServletApplication on aw-rmbp.local with PID 8473 (/Users/awilkinson/dev/workspaces/spring/spring-boot/2.0.x/custom-dispatcher-servlet/target/classes started by awilkinson in /Users/awilkinson/dev/workspaces/spring/spring-boot/2.0.x/custom-dispatcher-servlet)
2018-06-19 20:20:20.308 INFO 8473 --- [ main] c.e.d.CustomDispatcherServletApplication : No active profile set, falling back to default profiles: default
2018-06-19 20:20:20.352 INFO 8473 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@35083305: startup date [Tue Jun 19 20:20:20 BST 2018]; root of context hierarchy
2018-06-19 20:20:21.517 INFO 8473 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-06-19 20:20:21.541 INFO 8473 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-06-19 20:20:21.542 INFO 8473 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-06-19 20:20:21.550 INFO 8473 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/awilkinson/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2018-06-19 20:20:21.643 INFO 8473 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-06-19 20:20:21.643 INFO 8473 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1294 ms
2018-06-19 20:20:21.872 ERROR 8473 --- [ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPathProvider' available
2018-06-19 20:20:21.889 INFO 8473 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-06-19 20:20:21.894 WARN 8473 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2018-06-19 20:20:21.902 INFO 8473 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-06-19 20:20:22.007 ERROR 8473 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Method servletEndpointRegistrar in org.springframework.boot.actuate.autoconfigure.endpoint.web.ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration required a bean of type 'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPathProvider' that could not be found.
- Bean method 'mainDispatcherServletPathProvider' not loaded because Default DispatcherServlet found dispatcher servlet bean dispatcherServlet
Action:
Consider revisiting the conditions above or defining a bean of type 'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPathProvider' in your configuration.
我不完全确定如何解决这个问题。我们需要获取将调度到任何 servlet 端点的调度程序 servlet,并获取它映射到的路径。
EndpointRequest
回到“""
如果没有” DispatcherServletPathProvider
,但我也不确定这是否正确。