intellij-idea - IntelliJ IDEA 未选择正确的应用程序-{}.properties 文件

标签 intellij-idea spring-boot

我有一个使用配置文件属性文件的 spring boot 1.5.1 项目。在我的/src/main/resources 我有我所有的属性文件
enter image description here

使用 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 定义为我的资源文件夹。

更新:

添加配置截图:
enter image description here

最佳答案

我在这里可能是错的,但它看起来不像 spring.profiles.active环境变量实际上是在您的配置中设置的,无论您选择什么作为事件配置文件。这可能是 IntelliJ 的一个错误。

但是,在 Run -> Edit Configurations 中设置环境变量绝对适合我。

enter image description here

关于intellij-idea - IntelliJ IDEA 未选择正确的应用程序-{}.properties 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42447759/

相关文章:

java - 为什么添加父类(super class)会破坏我的 Spring bean?

java - Spring Boot DataJpaTest 单元测试恢复为 H2 而不是 mySql

java - IntelliJ 错误 : java. lang.NullPointerException

java - 在 IntelliJ IDEA 中使用 hibernate ( console ) 的用户访问被拒绝

java - 将 JFileChooser 添加到我的项目后,IntelliJ 调试器不会停止

java - 通过字段 'personRepository' 表示的不满足的依赖关系;嵌套异常是 org.springframework.beans.factory.BeanCreationException :

css - 在 IntelliJ IDEA 中将 .css 作为 .less 文件打开

actionscript-3 - AS3错误1180调用IntelliJ中可能未定义的方法

spring-boot - Spring Boot 嵌入式 ActiveMQ 持久消息

spring-boot - 在 spring boot 中从 application.properties 获取属性