I am loading the custom configuration from application.yml in my spring boot service.
I have annotated by bean class as below,
@Component
@ConfigurationProperties("app")
public class ContinentConfig {
private Map<String, List<Country>> continents = new HashMap<String, List<Country>>();
//get/set/tostring methods
}
My custom class Country includes 2 fields,
public class Country {
String name;
String capital;
//get/set/tostring methods
}
In application.yml I have as below,
app:
continents:
Europe:
- name: France
capital: Paris
Asia:
- name: China
capital: Beijing
With the above setup, I am able to load the config from application.yml.
I now want to extract the config to a separate continentconfig.yml in the same src/main/resources folder. So, I moved the custom config to continentconfig.yml leaving other properties like server.port in application.yml.
The continentconfig.yml has the same content as I had earlier in application.yml.
I also added the below annotations to the ContinentConfig Class,
@Component
@ConfigurationProperties("app")
@EnableConfigurationProperties
@PropertySource(value="classpath:continentconfig.yml")
public class ContinentConfig {
}
After this change, I see the config is not getting loaded from continentconfig.yml to ContinentConfig bean.
Can someone please help in resolving the issue.