Spring Cloud Micro Service Integration Configuration Center

Source: Internet
Author: User
Tags app service

1. Build the Spring Cloud Config Configuration center (see previous blog post)

2. Create a micro-service project Bounter-simon-app,pom file as follows:

<?XML version= "1.0" encoding= "UTF-8"?><Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">    <modelversion>4.0.0</modelversion>    <groupId>Cn.bounter</groupId>    <Artifactid>Bounter-simon-app</Artifactid>    <version>0.0.1-snapshot</version>    <Packaging>Jar</Packaging>    <name>Bounter-simon-app</name>    <Parent>        <groupId>Org.springframework.boot</groupId>        <Artifactid>Spring-boot-starter-parent</Artifactid>        <version>2.0.4.RELEASE</version>    </Parent>    <Properties>        <java.version>1.8</java.version>        <spring-cloud.version>Finchley.sr1</spring-cloud.version>    </Properties>    <Dependencies>        <Dependency>            <groupId>Org.springframework.boot</groupId>            <Artifactid>Spring-boot-starter-web</Artifactid>        </Dependency>

<Dependency> <groupId>Org.springframework.cloud</groupId> <Artifactid>Spring-cloud-starter-config</Artifactid> </Dependency> </Dependencies> <dependencymanagement> <Dependencies> <Dependency> <groupId>Org.springframework.cloud</groupId> <Artifactid>Spring-cloud-dependencies</Artifactid> <version>${spring-cloud.version}</version> <type>Pom</type> <Scope>Import</Scope> </Dependency> </Dependencies> </dependencymanagement> <Build> <Plugins> <plugin> <groupId>Org.springframework.boot</groupId> <Artifactid>Spring-boot-maven-plugin</Artifactid> </plugin> </Plugins> </Build></Project>

3. Configure the configuration information from the configuration center to obtain the application.properties file as follows:

server.port=8081# Configuration Center Warehouse profile Name spring.application.name=simon# Configuration Center Server address spring.cloud.config.uri=http://localhost:8888

4. The controller returns the configuration information obtained from the configuration center, the Simoncontroller.java content is as follows:

@RestController @crossorigin@requestmapping ("/api/simon")  Public class Simoncontroller {    @Value ("${name}")    private  String name;        @GetMapping ("/name")    public responsedata<?> get () {           Returnnew responsedata<>(). Success (). data (name);}    }

5. Start the Bounter-simon-app service, browser access: Http://localhost:8081/api/simon/name, the page is as follows:

True"Simon"null1534917807null}

Data shows the value of the name attribute obtained from the configuration center, it is not easy ah, then try it yourself!

Source Code GitHub Address:

Https://github.com/13babybear/bounter-simon-app

Https://github.com/13babybear/bounter-susan-app

Spring Cloud Micro Service Integration Configuration Center

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.