Issue reading yml/yaml files from a spring boot app inside IntelliJ
Hello,
I came with a very weird issue with IntelliJ, I have spent many hours now and haven't found a solution to it. I have multiple Spring Boot applications where the properties are inside an application.yml file and all of them were working completely fine. After restarting my environment, without making any change, they all started complaining about not finding the properties inside their respective yml files. The @Value Spring annotations and even the simple server.port configurations were ignored, which made me think that the issue is that the application.yml files are not being read anymore. As an experiment I added an application.properties to one of my apps and it worked! I know it is not a SpringBoot configuration issue since I can run these projects in Eclipse and they run as expected. Could you help me with this problem? I can provided any needed information anytime.
Thank you,
Daniel
请先登录再写评论。
"they all started complaining about not finding the properties inside their respective yml files"
Do you mean that the configuration keys are highlighted as unknown? Please verify Spring facet is configured in corresponding module and Spring Boot application context is auto-configured (do NOT setup manually).
In my case, IDEA became able to read application.yml properties after adding
to project's pom.xml
Simply rename the application.yml to application.yaml and it should work. IntelliJ doesn't recognise .yml
Thank you for your quick response Yann. Sorry I did not give enough details on this issue. I assume the yml file is not picked up by Spring Boot because, when initializing the app, I get a BeanCreationException on one of my controller classes:
java.lang.IllegalArgumentException: Could not resolve placeholder 'property.value' in string value "${property.value}"
This is thrown since I have @Value Spring annotation on this controller. If I comment this controller and run the app, I know the yml is still ignored because the app runs on the default port, not the one I am specifying on the file. Once I add an application.properties file, it works!
I checked my Spring Facet configurations and it is defined as Autodetected on all my projects. As I previously mentioned it earlier, I discarded a Spring Boot configuration issue since my projects run fin on another IDE. I am currently running IntelliJ IDEA 2017.1.6.
I think I am missing a configuration in IntelliJ that is causing this to happen.
Thank you in advance,
Daniel
I had a similar problem where I can use "mvn spring-boot:run -Dmaven.profiles.active=local" with success, but running the Application within the IDE did not work.
The solution for me was to add an Environment Variable to specify which profile to look for. Then it found my "application-local.yml" file perfectly.
Hi,
Just faced the same issue as topic starter: application.yml is ignored, so property placeholders cannot be injected.
I tried application.yml -> application-local.yml and those maven and environment variable mentioned above - does not work.
When I run application with 'mvn spring-boot:run' - everything is fine, when I ran from eclipse with 'Run as Java Application' - everything is fine, when I ran from Idea 'Run <Application>' - application does not start due to the issue mentioned above.
This looks like critical issue, since I cannot start\debug my application.
Any suggestions where to start?
UPD: So, this is very strange for a 'Smart IDE with Smart Spring Plugin (not free!)'. I needed to manually change 'Project compiler output' value to path where maven saves its build artifacts. Then it worked. Looks like Java + Spring Boot + Maven is such a rare combination is Java world, so the most popular IDE cannot figure it out or even give a hint.
Thank you.
Hi,
I have the same issue. I have a yml that declares two profiles. When I run mvn spring-boot:run or in Eclipse everything is fine and the app reads both config yml files. Then when I run it inside Idea, there is like the profiles don't exist at all (problem with placeholders, database, etc.)
I tried the solutions from Vanya and Roschin and they doesn't seem to work for me.
I appreciate any solution with this issue.
Thanks in advance.
I'm facing the same issue with 2020.1. What is the issue #?
Any solution for this. I'm seeing same on IntelliJ IDEA 2022.1 (Ultimate Edition).
I've tried adding the Spring Facet to the project module setting but same story
Ah ok so this is a runtime issue, not an issue within the IDE.
Please double-check your YAML files are copied correctly to your output directory. Also verify the chosen module in run configuration is correct (classpath). If it still doesn't work, try running the app via Gradle/Maven targets.
Hey guys,
Any idea why IntelliJ needs an active profile? (application-local.yml works, whereas application.yml does not).
Why does it not pick up the base application.yml?
Thanks!
Hello guys!
I have the same issue running an application on Intellij IDEA 2019.1.3 CE, and I solve using the solution reported above by @Eric Prickett.
Tks! :-)
None of the solutions offered by @Eric Prickett and @... worked for my scenario which works in Eclipse with Environment Properties plugin v2
IDE version: 2019.3.2
Spring facet is enabled on all app modules including web. First name-value pair lookup error: Required key 'database.url' not found
application-local.yml snippet:
version: '2'
services:
application:
environment:
DATABASE_URL: jdbc:db2://dbhost:port/dbname
Hello, Jake. Could you please report an issue at https://youtrack.jetbrains.com/issues/IDEA.
Please share a sample project to reproduce the issue if possible.
Jason,
Looks like the issue was not filed. Can I ask you to create a new ticket for that in YouTrack, as Konstantin asked? Thanks!
Tyler Griffin, when did this happen :) Thanks saved my time
It keeps happening in the latest version of IntelliJ (2021.2.2), the approaches above don't work for me.
In my case, I have to close and open the IntelliJ until it works.
Desmond Kirrane I am seeing the issue too in 2022.1.2 (Ultimate Edition).
I have added "Spring Boot Assistant" it works for me.