IntellJ IDEA 2017 激活编译器配置,读取多个配置文件

时间:2024-09-02 09:35:08

1、设置编译器,找到1,点击2

IntellJ IDEA 2017 激活编译器配置,读取多个配置文件

2、输入设置命令:--spring.profiles.active=test,如果是多个文件输入--spring.profiles.active=test,dev

IntellJ IDEA 2017 激活编译器配置,读取多个配置文件

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