The default property source for the external configuration that the bootstrap process adds is config Server, but you can PropertySourceLocator add additional feeds by adding the type's bean to the boot context (through spring.factories ). You can use this method to insert additional properties from other servers or databases.
As an example, consider the following trivial custom locators:
@Configuration Public classCustompropertysourcelocator implements Propertysourcelocator {@Override PublicPropertysource<?>Locate (Environment environment) {return NewMappropertysource ("CustomProperty", collections.<string, Object>singletonmap ("Property.from.sample.custom.source","worked as intended")); }}
The incoming Environment is to be created ApplicationContext Environment , which gives us an additional attribute source. It will already have a source of resources that the normal spring boot provides, so you can use them to locate a property source specific to this, such as the Environment spring.application.name Config server property source locator by binding it on, as you did by default.
If you create a jar in this class, then add one that META-INF/spring.factories contains:
Org.springframework.cloud.bootstrap.bootstrapconfiguration=sample.custom.custompropertysourcelocator
Then "CustomProperty" PropertySource will appear in any application that contains the jar in its classpath.
Spring Cloud Custom Boot Property source