关于多配置文件测试环境,开发环境切换
以往可能在做项目环境发布的时候需要手动改配置文件内容上线测试很玛法
如果增加了如下多环境配置文件,启动项目只需要根据自己想要链接的环境进行激活配置文件即可
java -jar x.jar --spring.profiles.active=xxx
如果是IDEA 或者使用默认启动激活那种
或者使用如下图配置
主配置.yml结尾文件写法
server:
port: 8090
spring:
profiles:
active: test
yml从配置文件
spring:
datasource:
driver-class-name: oracle.jdbc.OracleDriver
url: url
username: xxxx
password: xxxxx
mybatis:
mapperLocations: classpath*:com.operation.dao.*.xml
rabbitmq:
host: 主机
port: 5672
virtual-host: /
username: coder
password: 123456
publisher-confirms: true
publisher-returns: true
template:
mandatory: true
receive-timeout: 300000
reply-timeout: 300000
redis:
host: 主机
post: 6379
timeout: 20000
jedis:
pool:
max-active: 8
min-idle: 1
max-idle: 8
max-wait: -1ms
主配置.properties结尾文件写法
server.port= 8090
spring.profiles.active= test
properites从配置文件
spring.rabbitmq.listener.acknowledge-mode=none
spring.datasource.url= jdbc_url
spring.datasource.driver-class-name= oracle.jdbc.OracleDriver
spring.datasource.username= xxxx
spring.datasource.password= xxxx
spring.mybatis.mapperLocations = classpath*:com.operation.dao.*.xml
#哈尔滨正式环境
spring.rabbitmq.host=主机
spring.rabbitmq.port=5672
spring.rabbitmq.virtual-host=/
spring.rabbitmq.username=coder
spring.rabbitmq.password=123456
spring.rabbitmq.publisher-confirms=true
spring.rabbitmq.publisher-returns=true
spring.rabbitmq.template.mandatory=true
spring.rabbitmq.template.receive-timeout=300000
spring.rabbitmq.template.reply-timeout=300000
#redis配置
spring.redis.host=主机
spring.redis.port=6379
spring.redis.timeout=20000
spring.redis.jedis.pool.max-active=8
spring.redis.jedis.pool.min-idle=1
spring.redis.jedis.pool.max-idle=8
spring.redis.jedis.pool.max-wait=-1ms