server.port=8080
server.contextPath=/myapp
Consider the above configuration in the application.properties of a spring boot application. What is the need of contextPath if we can't really run another spring boot application in the same port 8080. Can anyone provide some real time scenarios where this contextPath useful?
[edit] In my experience, when we deploy multiple web applications (web applications contexts) to single tomcat instance running on 8080 port the context path is used to distinguish the applications. This is what kept me thinking about the possibility of running multiple spring applications in a single port. Otherwise, I don't see the value of having an option to change the contextPath. Also considering the fact that we will have nginx or apache as a web server front and this spring applications are going to be run only inside the firewall.
No you can have only one application listening on a specific port at a time.
Changing the context path can be helpful in order to globally add a prefix to all your controller endpoints.
For instance if your application is serving rest API and you want all the urls to start with /api
then one option would be to add this prefix to each request mapping (for example @RequestMapping("/api/user)
), or change the context path to /api
then you can have your request mapping now as @RequestMapping("/user)
Nope same PORT cannot be used by multiple process/applications
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With