步骤1:切换需求步骤2:多配置文件步骤3:部署
步骤 1 : 切换需求
有时候在本地测试是使用8080端口,可是上线使用的又是80端口。 此时就可以通过多配置文件实现多配置支持与灵活切换步骤 2 : 多配置文件
3个配置文件:
核心配置文件:application.properties
开发环境用的配置文件:application-dev.properties
生产环境用的配置文件:application-pro.properties
这样就可以通过application.properties里的spring.profiles.active 灵活地来切换使用哪个环境了
- application.properties
- application-dev.properties
- application-pro.properties
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
spring.profiles.active=pro
server.port=8080
server.context-path=/test
server.port=80
server.context-path=/
步骤 3 : 部署
不仅可以通过修改application.properties文件进行切换,还可以在部署环境下,指定不同的参数来确保生产环境总是使用的希望的那套配置。cd C:UsersX7TIDownloadsspringboot
mvn install
java -jar target/springboot-0.0.1-SNAPSHOT.jar --spring.profiles.active=pro
或者java -jar target/springboot-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev
这样就可以保证在开发环境总是用的8080端口,而到了生产环境总是用的80端口,免去了每次上线还要修改端口号的麻烦。
参考: 创建可运行Springboot jar包教程
![2cb79fb5d9988fc93dd8eb98afd03d28.png](https://i-blog.csdnimg.cn/blog_migrate/2670f5453f4203e878279117d86a2442.png)
更多内容,点击了解: https://how2j.cn/k/springboot/springboot-switch-config/1644.html