SPRINGCLOUD18---Springcloudconfig

Source: Internet
Author: User

 PackageCom.itmuch.cloud;ImportOrg.springframework.beans.factory.annotation.Value;Importorg.springframework.web.bind.annotation.GetMapping;ImportOrg.springframework.web.bind.annotation.RestController; @RestController Public classConfigclientcontroller {@Value ("${profile}")  PrivateString profile;//you can get the value of the local application.yml configuration file profile:ssss@GetMapping ("/profile")   PublicString GetProfile () {System.out.println ( This. Profile); return  This. Profile; }}
 Package Com.itmuch.cloud; Import org.springframework.boot.SpringApplication; Import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication  Public class configserverapplication {  publicstaticvoid  main (string[] args) {    Springapplication.run (configserverapplication). class , args);}  }

Application.yml

Server:   8081# profile:ssss# via Localhsot:8081/

Bootstrap.yml

# Springcloud There is a boot context, used to load the remote configuration is config server configuration # First load bootstrap.yml load config server inside the configuration, Then go to load the config inside the application.yml # Spring:  Cloud:    config:      uri:http://localhost:8080  #config Server Port       profile:dev      label:master   # when the backend store for Configserver is git, the default is master   Application:    name:foobar  #本工程的名字, go to config server's git repository to find foobar-dev.yml file
<project xmlns= "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> <parent> <groupId>com.itmuch.cloud</groupId> <artifactid>mi Croservice-spring-cloud</artifactid> <version>0.0.1-SNAPSHOT</version> </parent> < Artifactid>microservice-config-client</artifactid> <packaging>jar</packaging> < Properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties&gt    ; <dependencies> <!--config client dependent--<dependency> &LT;GROUPID&GT;ORG.SPRINGF Ramework.cloud</groupid> <artifactId>spring-cloud-starter-config</artifactId> &LT;/DEP Endency> <!--springmvc dependent-<dependency> <groupid>org.springframework.boot </groupId> <artifactiD>spring-boot-starter-web</artifactid> </dependency> </dependencies></project> 

 PackageCom.itmuch.cloud;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.SpringBootApplication;Importorg.springframework.cloud.config.server.EnableConfigServer, @SpringBootApplication @enableconfigserver Public classconfigserverapplication { Public Static voidMain (string[] args) {Springapplication.run (configserverapplication.class, args); }}

Application.yml

Server:   8080Spring:  Cloud:    config:      server:        git:          uri:https://  Git.oschina.net/it-much/config-repo-51cto-video          username:           Password:           # git inside foobar -dev.yml content profile:profile-Dev, used for engineering foobar. # git inside application.yml content profile:profile-default, file Foobar project can not find foobar-dev.yml time to use.

Application.yml.bak1-Basic Use Mode

Server:   8080Spring:  Cloud:    config:      server:        git:          uri:https://git.oschina.net/ It-much/config-repo-51cto-video

application.yml.bak2-wildcard characters

Server:   8080Spring:  Cloud:    config:      server:        git:          uri:https://  Git.oschina.net/it-much/{application}

application.yml.bak3-Pattern Matching

Server:   8080Spring:  Cloud:    config:      server:        git:          uri:https://git.oschina.net/ It-much/config-repo-51cto-video      # public           repos:            Simple:https://  Git.oschina.net/it-much/simple            Special:              pattern:special*/dev*,special*/test*               Uri:https: // git.oschina.net/it-much/special

application.yml.bak4-Search Path

Server:   8080Spring:  Cloud:    config:      server:        git:          uri:https://git.oschina.net/ It-much/config-repo-51cto-video      # public          search-paths:            - foo   # foo path            -Bar   # Bar Path

Application.yml.bak5-cloneonstart

Server:   8080Spring:  Cloud:    config:      server:        git:          uri:https://git.oschina.net/ It-much/config-repo-51cto-video      # Common          true          repos:            Simple:https: // Git.oschina.net/it-much/simple             Special:              pattern:special*/dev*,special*/test*              Uri:https:// git.oschina.net/it-much/special              false          

application.yml.bak6-account password

Server:   8080Spring:  Cloud:    config:      server:        git:          uri:https://git.oschina.net/ It-much/config-repo-51cto-video          username:           Password:           
<project xmlns= "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> <parent> <groupId>com.itmuch.cloud</groupId> <artifactid>mi Croservice-spring-cloud</artifactid> <version>0.0.1-SNAPSHOT</version> </parent> < Artifactid>microservice-config-server</artifactid> <packaging>jar</packaging> < Properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties&gt    ; <dependencies> <!--config server dependency--<dependency> &LT;GROUPID&GT;ORG.SPRINGF Ramework.cloud</groupid> <artifactId>spring-cloud-config-server</artifactId> </depe Ndency> </dependencies></project>

SPRINGCLOUD18---Springcloudconfig

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.