I would like to set the context path for the Spring Boot application, and the following property can achieve that.
server.contextPath=/api
However, I would like to redirect /
to /api
. Currently, I am getting a HTTP 404 Error. How can I achieve that in Spring Boot?
2
(1) With Spring Boot, inside application.properties
(or somehthing like this in application.yml
)
server.servlet.context-path=/api
(2) or
server.context-path=/api
See https://docs.spring.io/spring-boot/docs/1.2.1.RELEASE/reference/html/common-application-properties.html#:~:text=parameters.a%3Dalpha-,server.context%2Dpath,-%3D%20%23%20the%20context
(3)
spring.mvc.servlet.path=/api
See
- https://www.baeldung.com/spring-boot-context-path
- /a/67922089/3728901
Let’s share with me your result.