美文网首页
Springboot的访问切换配置

Springboot的访问切换配置

作者: java迷途小菜鸡 | 来源:发表于2019-06-27 22:17 被阅读0次

有时候在本地测试是使用8080端口,可是上线使用的又是80端口。 此时就可以通过多配置文件实现多配置支持与灵活切换

3个配置文件:

核心配置文件:application.properties

开发环境用的配置文件:application-dev.properties

生产环境用的配置文件:application-pro.properties

这样就可以通过application.properties里的spring.profiles.active 灵活地来切换使用哪个环境了

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=/

不仅可以通过修改application.properties文件进行切换,还可以在部署环境下,指定不同的参数来确保生产环境总是使用的希望的那套配置。

 
cd C:\Users\X7TI\Downloads\springboot
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

文章转载自http://how2j.cn/k/springboot/springboot-switch-config/1644.html#nowhere

相关文章

网友评论

      本文标题:Springboot的访问切换配置

      本文链接:https://www.haomeiwen.com/subject/kewdcctx.html