Issue
demo-parent:
--web
--src
--main
--java
--Application.java
--resources
--application.yml
--application-mysql.yml
--service
--common
--src
--main
--java
--Config.java
--resources
--core-application.yml
there are some spring properties
in core-application
like spring.kafka.properties.bootstrap.servers
. How can I get them in my web module?
I have an error FileNotFoundException: class path resource [core-application.yml] cannot be opened because it does not exist
now.
Solution
The @PropertySource
annotation is repeatable according to Java 8 conventions. Therefore, if we're using Java 8 or higher, we can use this annotation to define multiple property locations:
@PropertySource("classpath:foo.properties")
@PropertySource("classpath:bar.properties")
public class PropertiesWithJavaConfig {
//...
}
@PropertySources({
@PropertySource("classpath:foo.properties"),
@PropertySource("classpath:bar.properties")
})
public class PropertiesWithJavaConfig {
//...
}
Refer this article, https://www.baeldung.com/properties-with-spring
Answered By - Gaurav
Answer Checked By - Marie Seifert (JavaFixing Admin)