Home > Java > javaTutorial > body text

How to Set a Context Path in a Spring Boot Application?

DDD
Release: 2024-10-26 01:52:27
Original
682 people have browsed it

 How to Set a Context Path in a Spring Boot Application?

Add Context Path to Spring Boot Application

Q: I'm trying to set the context root programmatically in a Spring Boot application, but it's not appending to the request mapping. What am I missing?

A: You're attempting to create a custom solution, but Spring Boot already supports this feature. Create an application.properties file in src/main/resources and add the following properties:

server.contextPath=/mainstay
server.port=12378
Copy after login

For Spring Boot 2.0:

server.servlet.context-path=/mainstay
Copy after login

Remove the custom servlet container configuration, or use an EmbeddedServletContainerCustomizer to apply post-processing.

The application.properties values serve as defaults, which you can override using another application.properties file or JVM parameters (-Dserver.port=6666).

The ServerProperties class implements EmbeddedServletContainerCustomizer, with a default context path of "". In your code, you're directly setting the context path on TomcatEmbeddedServletContainerFactory. However, ServerProperties will override it with "" during processing.

The above is the detailed content of How to Set a Context Path in a Spring Boot Application?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!