this will work and print out CountryData : {MY=[en, zh]}
but surely read the answer from Deadpool.
the hack is here to override the default configuration name 'application' by 'country'
in the example, I have done it by setting it via a System property, but starting your application via
java -jar mycountryapp.jar --spring.config.name=country
should work perfectly
@SpringBootApplication
public class Application {
static {
System.setProperty("spring.config.name", "country");
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@Service
class CountryService {
private final CountryData countryData;
public CountryService(CountryData countryData) {
this.countryData = countryData;
}
@EventListener(ApplicationReadyEvent.class)
public void showCountryDataOnStartup() {
System.err.println("CountryData : " + countryData.getMap());
}
}
@Configuration
@ConfigurationProperties(prefix = "entries")
class CountryData {
Map<String, List<String>> map;
public Map<String, List<String>> getMap() {
return map;
}
public void setMap(Map<String, List<String>> map) {
this.map = map;
}
}