1、设置编译器,找到1,点击2
2、输入设置命令:--spring.profiles.active=test,如果是多个文件输入--spring.profiles.active=test,dev
3、测试运行
package com.springboot; import com.springboot.conf.*;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext; /******************************
* @Author : liuyang
* @ClassName : QuickStartApplication
* @Date : 2018 五月 20
* @Time : 01:05:59
* @Type : SpringBoot
* @Version : 1.0
* @Return :
* @Description :
*******************************/ @SpringBootApplication
public class ReadDevOrTestApplication { public static void main(String[] args) { SpringApplication springApplication = new SpringApplication(ReadDevOrTestApplication.class); //编译器配置,注释上两行,在Edit Configuration中加入--spring.profiles.active=test,启用多个逗号多个--spring.profiles.active=test,dev ConfigurableApplicationContext applicationContext = springApplication.run(args); // 读取其他配置文档
System.out.println("*********开发的配置文档是:" + applicationContext.getEnvironment().getProperty("jdbc.url")); // 读取其他配置文档
System.out.println("*********开发的配置文档是:" + applicationContext.getEnvironment().getProperty("jdbc.name")); applicationContext.close();
}
}
相关代码:
https://github.com/liushaoye/quick_start/blob/second/src/main/java/com/springboot/ReadDevOrTestApplication.java