1、启动脚本内容:
nohup java .....省略一万点内容.....
--spring.profiles.active=${profiles} --isJar=true >> ${logPath}/${ModuleName}.log 2>&1 &
2、在代码中获取spring.profiles.active的值,也就是profiles的值。可以通过如下代码获取数据:
String profiles = System.getenv().get("spring.profiles.active");
这个是系统级别的参数,所以如果系统还没有启动完成也是可以获取的。
3、手动配置配置类
/**
* 私有构造方法
* @param flag Nothing to use
*/
private PropertiesConfiguration(boolean flag){
try{
String prefix = System.getenv().get("spring.profiles.active");
if(StringUtils.isEmpty(prefix)) {
InputStream active = PropertiesConfiguration.class
.getClassLoader().getResourceAsStream("application.properties");
Properties profile = new Properties();
profile.load(active);
prefix = profile.getProperty("spring