微服务 Maven Profiles 多环境配置
idea版本:2021.3.3(Community Edition)
项目根pom.xml配置
</project>
<-!- 省略项目其他配置 -->
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profile.active>dev</profile.active>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<profile.active>test</profile.active>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profile.active>prod</profile.active>
</properties>
</profile>
</profiles>
</project>
配置项目bootstrap.yml文件
server:
port: 8888
spring:
application:
name: learning-maven-profiles-server
profiles:
active: @profile.active@
logback:
devLevel: debug
cloud:
nacos: #nacos服务中心配置
config:
prefix: learning-maven-profiles-server
server-addr: ${system.active.nacos.@profile.active@.server-addr}
namespace: ${system.active.nacos.@profile.active@.namespace}
file-extension: yaml
group: DEFAULT_GROUP
discovery:
server-addr: ${system.active.nacos.@profile.active@.server-addr}
namespace: ${system.active.nacos.@profile.active@.namespace}
group: ${system.active.nacos.@profile.active@.group}
system.active.nacos:
dev:
server-addr: 127.0.0.1:8848
namespace: fe338ffd-9d20-44e3-bbcd-02b69d70649a
group: DEFAULT_GROUP_DEV
test:
server-addr: 127.0.0.2:8848
namespace: 1a1c5e8c-cc23-4d18-9f6d-bb7b47863632
group: DEFAULT_GROUP_TEST
prod:
server-addr: 127.0.0.3:8848
namespace: c1b67886-dd99-4aec-87ad-05c62e12944e
group: DEFAULT_GROUP_TEST
ribbon:
ReadTimeout: 60000 #请求处理的超时时间
ConnectTimeout: 60000 #请求连接超时时间
MaxAutoRetries: 0 #对当前实例的重试次数
MaxAutoRetriesNextServer: 1 #切换实例的重试次数 1
feign:
hystrix:
enabled: false
hystrix:
command:
userGetKey:
execution:
isolation:
thread:
timeoutInMilliseconds: 5000
# timeout:
# enabled: false
logging:
level:
com.alibaba: info
config: classpath:logback-spring.xml
mapper:
mappers: tk.mybatis.mapper.common.Mapper
启动、打包
在项目Maven进行切换启动或package即可进行不同环境的启动与编译打包