springcloud读取git上的配置文件

来源:互联网 发布:广西大学网络教育 编辑:程序博客网 时间:2024/06/01 09:52

如何在springboot项目启动的时候加载指定的git上的配置文件呢?

1、JVM参数方式:
  tomcat 中 catalina.bat(.sh中不用“set”) 添加JAVA_OPS。通过设置active选择不同配置文件
set JAVA_OPTS="-Dspring.profiles.active=test"
  eclipse 中启动tomcat。项目右键 run as –> run configuration–>Arguments–> VM arguments中添加。local配置文件不必上传git追踪管理
-Dspring.profiles.active="local"
2、web.xml方式:

<init-param>  <param-name>spring.profiles.active</param-name>  <param-value>production</param-value></init-param>
3、标注方式(junit单元测试非常实用):
@ActiveProfiles({"unittest","productprofile"})