Intellij idea IntelliJ IDEA未拾取正确的应用程序-{}.properties文件
我有一个SpringBoot1.5.1项目,它使用概要文件属性文件。在my/src/main/resources中,我有所有属性文件 使用IntelliJ 2016.3.4时,我将 运行配置|活动配置文件 “本地”并运行它。我在控制台中看到: 以下配置文件处于活动状态:本地 但是属性文件中有一个值Intellij idea IntelliJ IDEA未拾取正确的应用程序-{}.properties文件,intellij-idea,spring-boot,Intellij Idea,Spring Boot,我有一个SpringBoot1.5.1项目,它使用概要文件属性文件。在my/src/main/resources中,我有所有属性文件 使用IntelliJ 2016.3.4时,我将 运行配置|活动配置文件 “本地”并运行它。我在控制台中看到: 以下配置文件处于活动状态:本地 但是属性文件中有一个值 data.count.users=2 用作: @Value("${data.count.users}") private int userCount; 未被拾取从而导致错误的: 原因:java.l
data.count.users=2
用作:
@Value("${data.count.users}")
private int userCount;
未被拾取从而导致错误的:
原因:java.lang.IllegalArgumentException:无法解析
字符串值“${data.count.users}”中的占位符“data.count.users”
但是,如果我通过gradle运行这个
bootRun {
systemProperty 'spring.profiles.active', System.properties['spring.profiles.active'] }
作为
gradle bootRun-dsspring.profiles.active=local
然后,一切按预期使用本地配置文件启动。有人能理解为什么这件事没有得到妥善处理吗?在IntelliJ项目结构中,我将/src/main/resources定义为我的资源文件夹
更新:
添加配置的屏幕截图:
heimdall
的类路径是否正确,即它是否包含应用程序中显示的资源
文件夹。属性
我在这里可能是错的,但它看起来不像
spring.profiles.active
环境变量实际上是在您的配置中设置的,不管您选择了什么作为活动配置文件。这可能是IntelliJ的一个bug
但是,在Run->Edit Configurations中设置环境变量对我来说绝对有效
这也可能是由于非标准配置设置,例如:
src/main/resources
├── application.properties
├── config1
│ ├── application-dev.properties
│ ├── application-prod.properties
│ ├── application.properties
│ └── logback-spring.xml
├── config2
│ ├── application-dev.properties
│ ├── application-prod.properties
│ ├── application.properties
│ └── logback-spring.xml
└── config3
├── application-dev.properties
├── application-prod.properties
├── application.properties
└── logback-spring.xml
这可以通过分别使用logback和spring的参数logging.config
和spring.config.name
来解决。对于上述示例:
java -jar \
-Dspring.profiles.active=dev \
-Dlogging.config=classpath:config1/logback-spring.xml \
-Dspring.config.name=application,config1/application \
target/my-application.0.0.1.jar
这里使用rootapplication.properties
,由config1/application.properties
覆盖,由config1/application-dev.properties
覆盖。参数(环境变量)可以在IDEA的运行配置中的VM选项中指定
就高级IDE支持(突出显示、完成等)而言,复杂/自定义配置设置存在一个公开问题:就是这样,设置Spring方面是缺失的一部分。我猜它在15和16之间的存储方式不同?如何执行步骤1?谢谢,我尝试了“文件->设置”对话框,但没有成功