0

I would like to add a RESTful API using Spring Boot to an existing webapp running on Tomcat. I have tried to use the SpringBootServletInitializer in order simplify the integration. However, when doing so Spring Boot seems to interfere with the existing webapp (e.g., / doesn't work as it used to any more).

Is it possible somehow to configure the Spring Boot integration so that it only handles endpoints that starts with /api and ignores everything else?

Also, is it possible to use the SpringBootServletInitializer for this?

The existing servlets are registered with servlet-mappings using the web.xml file.

  • Can you add information on how the existing servlets are registered ([edit](https://stackoverflow.com/posts/68739403/edit) your question)? Spring Boot replaces the _default_ servlet, so it should not override the others. – Piotr P. Karwasz Aug 11 '21 at 09:59
  • The existing servlets are registered with servlet-mappings using the `web.xml` file. Also, override is probably wrong here... I changed it to interfere. – Henrik Strand Aug 13 '21 at 05:38
  • Does this answer your question? [How to set base url for rest in spring boot?](https://stackoverflow.com/questions/32927937/how-to-set-base-url-for-rest-in-spring-boot) – Piotr P. Karwasz Aug 13 '21 at 12:14
  • In particular `spring.mvc.servlet.path=/api` will bind your Spring `DispatcherServlet` to `/api/*`, so that it does not interfere with your other servlets. – Piotr P. Karwasz Aug 13 '21 at 12:35
  • I've tried with `server.servlet.context-path` but that only works with the embedded Tomcat (not an external one which is my case). – Henrik Strand Aug 14 '21 at 13:20
  • According to https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.spring-mvc.switch-off-dispatcherservlet `spring.mvc.servlet.path` seems to be the correct one to use. I'll just have to verify that it works with an external Tomcat as in my case... – Henrik Strand Aug 14 '21 at 13:29

0 Answers0