Spring Cloud Custom Boot Property source

Source: Internet
Author: User

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

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.