Summary: Spring Data REST app with a servlet mapping set to something like/api/*
seems to break as soon as I add the @EnableWebMvc
annotation to my configuration.
Context: I'm migrating an existing (and working) application from Spring 5.2 / Data REST 3.2 to Spring 5.3 / Data REST 3.7. After the migration, I get 404 errors for resources exposed by SDR, while resources exposed by MVC work fine. The dispatcher servlet is bound to the /api/*
url pattern (because static resources are served on /
).
This can be easily reproduced on my fork of the spring-data-book repository: https://github.com/bjansen/spring-data-book/commits/master
I added the following commits to the master branch:
Updated dependencies
: updates to the latest Spring/SDR 5.x. Everyting works fine, http://localhost:8080/ lists the resources exposed by SDR.Changed servlet url-pattern
: sets the url pattern to/api/*
instead of/
. Everyting still works fine, http://localhost:8080/api lists the resources exposed by SDR.Added an MVC controller
: adds a@Controller
class +@EnableWebMvc
to the Java config. I can use the new (MVC) resource athttp://localhost:8080/api/hello
, but everything else is now returning 404s (i.e. SDR resources are broken).
A debugging session showed that there's a difference of behavior bewteen Servlet API 3 and 4 in org.springframework.web.util.ServletRequestPathUtils.ServletRequestPath#parse
. This can be confirmed by upgrading the dependencies to Jetty 10 and javax.servlet-api 4 (see commit named Update to Servlet API 4
). Now everything works as expected again.
Similarly, downgrading to Servlet 3, Spring 5.2 and SDR 3.2 also "fixes" the problem. See commit named Downgrade Servlet API and Spring/SDR
.
I'm wondering if I missed something while migrating to 5.3, or if it's a regression. My web application is currently deployed on Tomcat 8.x (Servlet API 3), and there's no plans to upgrade it to a newer version.
Comment From: snicoll
Thanks for the report but that's more a question for Spring Data REST. With @EnableMVC
a number of defaults will be enabled, which can go in the way of how Spring Data REST adds its controllers. The Spring Boot integration (if you're not using that yet) could be helpful as well.