Question:
I am unable to set a Spring Boot application's context root programmatically. The goal is to access the application at localhost:port/{app_name} and have controller paths appended to it. However, the application remains accessible at localhost:port.
Answer:
Instead of rolling your own solution, utilize Spring Boot's built-in support for setting the context path.
Solution:
Add the following properties:
<code class="properties">server.contextPath=/mainstay server.port=12378</code>
Update for Spring Boot 2.0:
In Spring Boot 2.0, the context path is now configured as:
<code class="properties">server.servlet.context-path=/mainstay</code>
Note:
Reference:
The above is the detailed content of How to Programmatically Set the Context Path for a Spring Boot Application?. For more information, please follow other related articles on the PHP Chinese website!