我有一个使用配置文件属性文件的 spring boot 1.5.1 项目。在我的/src/main/resources 我有我所有的属性文件
使用 IntelliJ 2016.3.4 时,我设置了
Run Configuration | Active Profile
到“本地”并运行它。我在控制台看到这个:
The following profiles are active: local
但是属性文件中有一个值
data.count.users=2
并用作:
@Value("${data.count.users}")
private int userCount;
没有被拾取,从而导致错误:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'data.count.users' in string value "${data.count.users}"
但是,如果我通过 gradle 运行它
bootRun {
systemProperty 'spring.profiles.active', System.properties['spring.profiles.active'] }
作为
gradle bootRun -Dspring.profiles.active=local
然后一切都按预期使用本地配置文件启动。任何人都可以看到为什么这没有被正确拾取?在 IntelliJ 项目结构中,我将/src/main/resources 定义为我的资源文件夹。
更新:
添加配置截图:
最佳答案
我在这里可能是错的,但它看起来不像 spring.profiles.active
环境变量实际上是在您的配置中设置的,无论您选择什么作为事件配置文件。这可能是 IntelliJ 的一个错误。
但是,在 Run -> Edit Configurations 中设置环境变量绝对适合我。
关于intellij-idea - IntelliJ IDEA 未选择正确的应用程序-{}.properties 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42447759/