1. Switch requirements
Sometimes, port 8080 is used for local testing, but port 80 is used for online testing. At this time, you can achieve multi-configuration support and flexible switching through multiple configuration files
2. Multiple configuration files
3 configuration files:
Core configuration file: application.properties
Configuration file for development environment: application-dev.properties
Configuration file for production environment: application-pro.properties
In this way, you can flexibly switch which environment to use through spring.profiles.active in application.properties
application.properties:
spring.mvc.view.prefix=/WEB-INF/jsp/ spring.mvc.view.suffix=.jsp spring.profiles.active=pro
application-dev.properties:
server.port=8080 server.context-path=/test
application-pro.properties
server.port=80 server.context-path=/
3. Deployment
Not only can you switch by modifying the application.properties file, but you can also specify different parameters in the deployment environment to ensure that the desired configuration is always used in the production environment.
cd C:/Users/X7TI/Downloads/springboot mvn install java -jar target/springboot-0.0.1-SNAPSHOT.jar --spring.profiles.active=pro
or
java -jar target/springboot-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev
This ensures that port 8080 is always used in the development environment, and port 80 is always used in the production environment, which eliminates the hassle of changing the port number every time it goes online.
Supplement: SpringBoot sets port and context path
1. Port and context paths
spring.mvc.view.prefix=/WEB-INF/jsp/ spring.mvc.view.suffix=.jsp server.port=8888 server.context-path=/test
Summarize
The above is the configuration method of SpringBoot multi-configuration switching introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!