Reputation: 1307
My application has application.yml in the main and test resources folder however application (Spring boot 2.4 with Maven) is complaining that application.properties is not found.
Below is the error.
2021-07-08 04:37:33.381 ERROR --- [ main] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@bd4ee01] to prepare test instance [com.test.SomeTests@6a7aa675]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
...
Caused by: java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:187)
I have tried to find solution online but could not able to find one. Please help.
Upvotes: 2
Views: 3807
Reputation: 3
You can explicitly specify your application properties location by setting the program arguments with as :
--spring.config.location=your_properties_path
Upvotes: 0
Reputation: 1619
This is not a sufficient description for your problem, where did you put the application.yml file ? if you are in a maven projet project, you should put it under src/main/resources
folder.
Also I'm not sure if spring is able to interpret .yml file extension of your file, try to change it to application.yaml instead.
Note from spring.io :
Upvotes: 2