[IntelliJ IDEA] Config web server root context path in Spring Boot
Spring Boot, by default, serves content on the root context path (“/”). we’ll cover the different ways of configuring it.
Golbal Namespace
Config root context path of the application for appending golbal namespace as API prefix.
Use application.properties
file
1 | # src/main/resources/application.properties |
Or use application.yaml
file.
1 | # src/main/resources/application.yaml |
Then, vist http://localhost:8080/api/v1/users
.
You can see Spring Boot Change Context Path | Baeldung - https://www.baeldung.com/spring-boot-context-path to learn the following options:
-
Java Config
-
Command Line Arguments
-
Java System Properties
-
OS Environment Variables
-
application.properties in Current Directory
-
application.properties in the classpath (src/main/resources or the packaged jar file)
Single Controller or Action
Config root context path prefix for single controller or action with annotations @RequestMapping or @GetMapping etc.
1 |
|
Then, vist http://localhost:8080/api/users
.
Custom properties
Config root context path prefix with your custom properties.
1 |
|
1 | # src/main/resources/application.properties |
Or
1 | # src/main/resources/application.yaml |
Then, vist http://localhost:8080/api/v1/users
.
References
[2] Spring Boot Change Context Path | Baeldung - https://www.baeldung.com/spring-boot-context-path