To override the context path in a Spring Boot application deployed on Tomcat, you can modify the application.properties
or application.yml
file.
Here’s how you can override the context path in Spring Boot:
- Using application.properties: Add the following line to your
application.properties
file:
server.servlet.context-path=/your-context-path
Replace /your-context-path
with the desired context path.
- Using application.yml: If you prefer YAML format, add the following to your
application.yml
:
server:
servlet:
context-path: /your-context-path
Again, replace /your-context-path
with your desired context path.
By setting the server.servlet.context-path
property, you’re configuring Spring Boot to deploy your application under the specified context path.
Once you’ve made the change and restarted your Spring Boot application, it will be accessible under the new context path. For example, if you set the context path to /myapp
, your endpoints will be available under http://localhost:8080/myapp/endpoint
.