Spring-cloud-config--quick Start

Source: Internet
Author: User
Tags decrypt list of attributes

Resources:

Https://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.4.0.RELEASE/single/spring-cloud-config.html

http://cloud.spring.io/spring-cloud-static/Camden.SR7/#_spring_cloud_config

Spring Cloud Config provides server and client support for external configurations in distributed systems. With config Server, you can manage the external properties of your application in all environments.

The concepts on the client and service side are the same as spring environment and propertysource, so they are well suited for spring applications and can be used with applications running in any language.

When applications are transferred from development to testing to the deployment pipeline, you can manage the configuration between these environments to ensure that the application has all the content that is needed to migrate. The default implementation of the server storage backend uses git, so it can easily support a tagged version of the configuration environment and can access the content through a variety of tools.

Characteristics:

Spring Cloud Config Server Features:

Provides a resource-based HTTP interface for external configuration items (such as Name-value or yaml content of the same functionality);

Encrypt and Decrypt attribute values (symmetric or asymmetric);

Using @enableconfigserver annotations makes it easy to embed this server in a spring boot application.

Config Client features (for Spring applications):

Bind to the configuration server and use remote property resources to initialize the spring environment;

Encrypt and Decrypt attribute values (symmetric and asymmetric).

Quick Start:

Start the service:

$ cd spring-cloud-config-server$. /MVNW Spring-boot:run

The server is a spring boot application that you can run from your IDE (the main class is ConfigServerApplication ). Then try to start a client:

$ curl localhost:8888/foo/development{"name":"Foo","label":"Master","propertysources":[  {"name":"https://github.com/scratches/config-repo/foo-development.properties","Source":{"Bar":"spam"}},  {"name":"https://github.com/scratches/config-repo/foo.properties","Source":{"Foo":"Bar"}}]}

The default strategy for finding a property resource is to clone a Git repository (at spring.cloud.config.server.git.uri ) and use it to initialize a mini SpringApplication . This mini-application is Environment used to enumerate property resources and publish them through JSON nodes.

The HTTP service has resources in the following form:

/{application}/{profile}[/{label}]/{application}-{profile}.yml/{label}/{application}-{profile}.yml/{ Application}-{profile}.properties/{label}/{application}-{profile}.properties

"Applications" is SpringApplication spring.config.name (generally speaking application is a regular spring boot application), "Profile" is an active profile (or a comma-delimited list of attributes), The label is an optional git tag (default is "Master").

Spring Cloud Config Server extracts the configuration for the remote client from the GIT repository (must be provided):

Spring:  Cloud:    config:      server:        git:          uri:https://github.com/spring-cloud-samples/config-repo

To use these features in your application, you simply build them into a spring boot application that relies on spring-cloud-config-client. The most convenient way to add dependencies is through the Spring Boot Launcher org.springframework.cloud:spring-cloud-starter-config . For MAVEN users There is also a parent pom and BOM ( spring-cloud-starter-parent ), and for Gradle and spring CLI users there is a spring IO version management file. For example MAVEN configuration:

<Parent>       <groupId>Org.springframework.boot</groupId>       <Artifactid>Spring-boot-starter-parent</Artifactid>       <version>1.3.5.RELEASE</version>       <RelativePath/> <!--Lookup parent from repository -   </Parent><dependencymanagement>    <Dependencies>        <Dependency>            <groupId>Org.springframework.cloud</groupId>            <Artifactid>Spring-cloud-dependencies</Artifactid>            <version>Brixton.release</version>            <type>Pom</type>            <Scope>Import</Scope>        </Dependency>    </Dependencies></dependencymanagement><Dependencies>    <Dependency>        <groupId>Org.springframework.cloud</groupId>        <Artifactid>Spring-cloud-starter-config</Artifactid>    </Dependency>    <Dependency>        <groupId>Org.springframework.boot</groupId>        <Artifactid>Spring-boot-starter-test</Artifactid>        <Scope>Test</Scope>    </Dependency></Dependencies><Build>    <Plugins>           <plugin>               <groupId>Org.springframework.boot</groupId>               <Artifactid>Spring-boot-maven-plugin</Artifactid>           </plugin>    </Plugins></Build>   <!--repositories also needed for snapshots and milestones -

Then create a standard spring boot application, just like this simple HTTP server:

@SpringBootApplication @restcontroller  Public class Application {    @RequestMapping ("/")    public  String Home () {          Return "Hello world!" ;    }      Public Static void Main (string[] args) {        springapplication.run (application. class , args);}    }

At run time, it selects the external configuration from the default local configuration server on port 8888 (if it is running). To modify the startup behavior, you can change the location of the configuration server using Bootstrap.properties (similar to Application.properties, but an application context-initiated configuration file), for example:

Spring.cloud.config.uri:http://myconfigserver.com

The reference property is displayed as a high-priority property source in the/env endpoint, for example:

$ curl localhost:8080/Env{  "Profiles":[],  "configservice:https://github.com/spring-cloud-samples/config-repo/bar.properties":{"Foo":"Bar"},  "Servletcontextinitparams":{},  "systemproperties":{...},  ...}

(the property source named "url>/< file name for configservice:< remote Repository >" contains the property "foo" with the value "bar" and is the highest priority)

Note: The URL in the property source name is the Git warehouse address instead of the URL of the configuration server.

  

Spring-cloud-config--quick Start

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.