Affects: \
Background: Tomcat 8.5, using Spring Boot 2.6.8 and Spring 5.3.20 to setup one DispatcherServlet instance to multiple servlet mapping paths. For example: map it to both "/a_path/*" and "/b_path/*", the "loadOnStartUp" are not set.
Steps to reproduce the problem: Step 1 start the service
Step 2 request to "/a_path/api1"
It's the first time to access "/a_path/*", Tomcat will initialize the DispatcherServlet instance by invoking its method DispatcherServlet#initStrategies
. Then its internal states like handlerMappings
, handlerAdapters
will be set.
Step 3 request to "/b_path/api2"
It's the first time to access "/b_path/*", Tomcat will initialize the same DispatcherServlet instance by invoking its method DispatcherServlet#initStrategies
again.
The problem is here, the initialization methods like DispatcherServlet#initHandlerAdapters
will clear previous state first before set them again:
private void initHandlerAdapters(ApplicationContext context) {
//Step 3a:clear handlerAdapters first
this.handlerAdapters = null;
...
//Step 3b: set handlerAdapters again
...
}
Assume now Step 3 processing is between step 3a and step 3b, the handlerAdapters
is cleared as null at this moment, it happens a new request "/a_path/api3" just comes, it will be processed in DispatcherServlet#doDispatch
and found no handlerAdapters
here, so it will end up with an error: "No adapter for handler [xxx]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler"
Comment From: snicoll
I don't understand how the same DispatcherServlet
instance could be reused. I don't think reusing the same instance, and having the servlet initalization callback invoked several times is supported. Can you please share a small sample that showcase what you've described? You can attach a zip to this issue or push the code to a separate GitHub repository.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.