-
Notifications
You must be signed in to change notification settings - Fork 40.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Requests that should be handled by an additional DispatcherServlet result in a 404 response #22682
Comments
Thanks for the report but I cannot reproduce the behaviour that you have described. The following works as excepted: package com.example.demo;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class Gh22682Application {
public static void main(String[] args) {
SpringApplication.run(Gh22682Application.class, args);
}
@Bean
public ServletRegistrationBean<ExampleServlet> exampleServletRegistrationBean() {
ServletRegistrationBean<ExampleServlet> registration =
new ServletRegistrationBean<Gh22682Application.ExampleServlet>(new ExampleServlet());
registration.addUrlMappings("/ping");
return registration;
}
@SuppressWarnings("serial")
static class ExampleServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().println("pong");
resp.flushBuffer();
}
}
}
If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue. |
@Configuration
public class ServletConfig {
@Resource
private MultipartConfigElement multipartConfigElement;
@Bean
public ServletRegistrationBean apiServletBean(WebApplicationContext wac) {
DispatcherServlet servlet = new DispatcherServlet(wac);
servlet.setThrowExceptionIfNoHandlerFound(true);
ServletRegistrationBean bean = new ServletRegistrationBean(servlet);
bean.setLoadOnStartup(1);
bean.addUrlMappings("/api/*");
bean.setMultipartConfig(multipartConfigElement);
bean.setName("apiServlet");
return bean;
}
} |
Thanks, but that doesn't give us enough information to diagnose the problem. For example, I can't tell what handlers are in your application and how they are getting registered with your (additional?) |
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. |
The above has provided the core code for the replication has not the replication? |
Unfortunately not, no. As I said above, it doesn't give us enough information to reproduce the problem. For example, I can't tell what handlers are in your application and how they are getting registered with your (additional?) DispatcherServlet. |
run tomcat? |
Sorry, but I'm not sure how running Tomcat will help. Your screenshot shows a request being made to |
please check https://github.com/DreamPWJ/spring-boot-bug.git spring boot2.3.2 spirng boot2.3.0 |
Thanks for the sample. I can now see what's happening. This is a regression caused by the changes made for #21499. In your case, there are two dispatcher servlets, one that is mapped to Lines 237 to 241 in 181e3b3
This then prevents mapping a request to |
I use the ServletRegistrationBean method to add the servlet prefix '/ API.' uniformly. Version 2.3.1 prompts or does not exist 404, while version 2.3.0 allows normal access to the/API / path
The text was updated successfully, but these errors were encountered: