Issue
Is there any way to set via property 'context-path' many mappings for a same Spring Boot MVC application? My goal is to avoid creating many 'Dispatcherservlet' for the uri mapping.
For example:
servlet.context-path =/, /context1, context2
Solution
You only need a single Dispatcherservlet with a root context path set to what you want (could be /
or mySuperApp
).
By declaring multiple @RequestMaping, you will be able to serve different URI with the same DispatcherServlet.
Here is an example. Setting the DispatcherServlet to /mySuperApp
with @RequestMapping("/service1")
and @RequestMapping("/service2")
would exposed the following endpoints :
/mySuperApp/service1
/mySuperApp/service2
Having multiple context for a single servlet is not part of the Servlet specification. A single servlet cannot serve from multiple context.
What you can do is map multiple values to your requesting mappings.
@RequestMapping({"/context1/service1}", {"/context2/service1}")
I don't see any other way around it.
Answered By - Daniel Lavoie
Answer Checked By - Marilyn (JavaFixing Volunteer)