转载:https://www.cnblogs.com/linzhanfly/p/9056722.html
一、网上很多采用@Profile("dev")的方式获取,但是这个是类级别的
二、开发中可能需要代码级别
1、刚开始我想通过classpath下的文件读取方式,麻烦死了,于是换了个思路。
2、SpringBoot启动日志中有下面这句:
1 |
|
(1)跟踪代码:SpringApplication.run方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
(2)跟踪代码:SpringApplication.prepareContext方法
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
(3)跟踪代码:SpringApplication.logStartupProfileInfo方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
(4)编写SpringContxtUtil工具类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|