如何从java获取spring配置文件名称
16lz
2021-01-22
I have a separate spring yaml configuration file for each profile.
我为每个配置文件都有一个单独的spring yaml配置文件。
I need from a CommandLineRunner
descendant class to read the profile and execute the appropriate script.
我需要从CommandLineRunner后代类读取配置文件并执行相应的脚本。
Is there a way from java to get the environment profile name?
有没有办法从java获取环境配置文件名称?
I have tried this :
我试过这个:
environment.getActiveProfiles();
but it only return an empty string array.
但它只返回一个空字符串数组。
2 个解决方案
#1
3
- Do you have an active profile? when no, it shows nothing.
- You can also use
environment.getProperty("spring.profiles.active")
to get active profiles.
你有活跃的个人资料吗?什么时候没有,它什么都没有。
您还可以使用environment.getProperty(“spring.profiles.active”)来获取活动的配置文件。
更多相关文章
- 求助:json + java 返回 数据 数组中去掉双引号
- 了解数组类型和使用java.util.Arrays类
- java的数组下标的非常严重的问题,异常不爽
- java数组常用功能
- 对一个JavaScript对象数组进行排序。
- 求一段与读取数据库数据,写入一个数组的javascript 代码!谢谢!!
- 将字符串拆分为字符串数组。
- 解析JSON数组使用GSON从URL
- 关于String、集合、数组的长度