Spring Cloud Custom Boot Property source

Source: Internet
Author: User

The default property source for external configurations added by the boot process is config Server, but you can add additional sources by adding propertysourcelocator-type beans to the boot context (via 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:

@Configurationpublic class CustomPropertySourceLocator implements PropertySourceLocator {    @Override    public PropertySource<?> locate(Environment environment) {        return new MapPropertySource("customProperty",                Collections.<String, Object>singletonMap("property.from.sample.custom.source", "worked as intended"));    }}

The incoming environment is the environment of the ApplicationContext to be created, which gives us an additional attribute source. It will already have a source of resources that normal spring boot provides, So you can use them to locate a property source specific to this environment (for example, by binding it on spring.application.name, such as the Config server property source locator by default).

If you create a jar in this class, then add a meta-inf/spring.factories containing:

Org.springframework.cloud.bootstrap.bootstrapconfiguration=sample.custom.custompropertysourcelocator
Then the "CustomProperty" Propertysource will appear in any application that contains the jar in its classpath.

Spring Cloud Custom Boot Property source

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.