spring boot 不同的环境使用不同的配置

来源:互联网 发布:泰语翻译中文软件 编辑:程序博客网 时间:2024/06/04 19:45

spring boot中,可以通过在application.yml配置文件中,配置多个不同的profile,实现在不同的环境(比如开发、测试和生产环境)使用不同的配置变量。

具体配置如下(application.yml中的内容):

server:  port: 8082# 默认的profile为dev,其他环境通过指定启动参数使用不同的profile,比如:#   测试环境:java -jar my-spring-boot.jar --spring.profiles.active=test#   生产环境:java -jar my-spring-boot.jar --spring.profiles.active=prodspring:  profiles:    active: dev---# 开发环境配置spring:  profiles: devmysql:  ipPort: localhost:3306  ---# 测试环境配置spring:  profiles: testmysql:  ipPort: 192.168.0.12:8066  ---# 生产环境配置spring:  profiles: prodmysql:  ipPort: 192.168.0.13:8066

使用方法:

通过指定启动参数使用不同的profile,比如:
#   测试环境:java -jar my-spring-boot.jar --spring.profiles.active=test
#   生产环境:java -jar my-spring-boot.jar --spring.profiles.active=prod

源代码地址:https://github.com/xujijun/my-spring-boot

2 0
原创粉丝点击