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 class custompropertysourcelocator implements Propertysourcelocator {@Override public PROPERTYSOURC E<?> Locate (environment environment) { retu RN new mappropertysource ("CustomProperty" <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.
Source source technical support for complete projects 1791743380
Spring Cloud Custom Boot Property source