Ram*_*pal 5 spring spring-boot
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.
不,您一次只能在一个特定的端口上侦听一个应用程序。
更改上下文路径可能有助于将前缀全局添加到所有控制器端点。例如,如果您的应用程序正在使用rest API,并且您希望所有的url开头,/api那么一个选择就是将该前缀添加到每个请求映射中(例如@RequestMapping("/api/user)),或者将上下文路径更改为,/api那么您现在就可以进行请求映射了如@RequestMapping("/user)
| 归档时间: | 
 | 
| 查看次数: | 400 次 | 
| 最近记录: |