I'm trying to run spring boot application 3.x.x, in one of the configuration I've used @PropertySource annotation to load property values but during application start up it fails giving the below error message:

Caused by: java.io.FileNotFoundException: class path resource [application-lib.properties] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:211) ~[spring-core-6.0.8.jar:6.0.8] at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:160) ~[spring-core-6.0.8.jar:6.0.8] at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:100) ~[spring-core-6.0.8.jar:6.0.8] at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:74) ~[spring-core-6.0.8.jar:6.0.8] at org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(PropertiesLoaderUtils.java:60) ~[spring-core-6.0.8.jar:6.0.8] at org.springframework.core.io.support.ResourcePropertySource.(ResourcePropertySource.java:67) ~[spring-core-6.0.8.jar:6.0.8] at org.springframework.core.io.support.DefaultPropertySourceFactory.createPropertySource(DefaultPropertySourceFactory.java:37) ~[spring-core-6.0.8.jar:6.0.8] at org.springframework.core.io.support.PropertySourceProcessor.processPropertySource(PropertySourceProcessor.java:87) ~[spring-core-6.0.8.jar:6.0.8]

When I generate final jar and run from command line there is no issue but while trying from STS, it gives this error. Although this file is present in one of the depedency module located in src/main/resources directory. I have implemented the code below way.

@Configuration
@PropertySource("classpath:application-lib.properties")
@EnableEncryptableProperties
public class AppConfig {

Versions:
Spring Boot: 3.0.6
Java: 17
STS: 4.x

1

There are 1 best solutions below

0
On

When I used clean option in STS, now it started working.