머리말
분산 시스템에서 수많은 서비스로 인해 서비스 구성 파일의 통합 관리를 용이하게하기 위해 분산 구성 센터 구성 요소 : Spring-Cloud-Config가 필요합니다. 구성 서비스를 지원하여 구성 서비스 (예 : 로컬)의 메모리에 배치되며 원격 git 저장소의 배치도 지원합니다.
이 섹션에서는 주로 GIT 저장소를 구성 소스로 사용하는 방법을 보여줍니다.
오픈 소스 주소 : https://github.com/bigbeef
구성 프로젝트를 만듭니다
모든 프로젝트의 구성 파일을 저장하기 위해 GitHub에서 프로젝트를 작성하십시오. 프로젝트는 내 프로젝트 구조입니다
구성 프로젝트 주소 : https://github.com/bigbeef/cppba-config
Eureka-Server.properties
Eureka.client.register-with-eureka = falseureka.client.fetch-registry = falspring.application.name = eureka-serverserver.port = 18761eureka.instance.hostname = peer1eureka.client.serviceurl.defaultzone = http : // 18761/eureka.
스프링 클라우드 콘피드 서버 프로젝트를 만듭니다
프로젝트 구조는 그림에 나와 있습니다.
pom.xml 핵심 코드
<pectionies> <pectionency> <groupId> org.springframework.cloud </groupid> <artifactid> spring-cloud-config-server </artifactid> </fectionency> </fectionements>
SpringCloudConfigserVerapplication.java
패키지 com.cppba; import org.springframework.boot.springApplication; import org.springframework.boot.autoconfigure.springbootapplication; import org.springframework.cloud.config.server.enableconfigserverver@springboplic classe@enbableconfigonfigsebleconfigerfigserfigseblicpplication SpringCloudConfigSerVerApplication {public static void main (String [] args) {springApplication.Run (SpringCloudConfigServerApplication.class, args); }}application.properties
이것은 실제 GIT 프로젝트를 기반으로합니다
Server.port = 8888spring.application.name = config-serverspring.cloud.config.server.git.uri = https : //github.com/bigbeef/cppba-configspring.cloud.config.label=master# spring.cloud.config.git.git.git.git.git.git.git. spring.cloud.config.server.git.password = spring.cloud.config.server.git.searchpaths =/cppba-spring-cloud/*,/cppba-spring-cloud/eureka-client/*
spring.cloud.config.server.git.uri : git 리포지토리 주소를 구성하십시오
spring.cloud.config.server.git.searchpaths : 쉼표로 분리 된 저장소 경로를 구성합니다
spring.cloud.config.label : 저장소의 분기를 구성하십시오
spring.cloud.config.server.git.username : git 리포지토리에 액세스 할 수있는 사용자 이름입니다
spring.cloud.config.server.git.password : git 저장소에 액세스하는 사용자 비밀번호
프로젝트를 시작하십시오
액세스 주소 : http://127.0.0.1:8888
HTTP 요청 주소 및 리소스 파일 매핑은 다음과 같습니다.
/{application}/{프로파일} [/{label}]
/{application }- {profile }.yml
/{label }/ {Application }- {profile }.yml
/{application }- {profile} .properties
/{label }/ {Application }- {profile} .properties
우리 자신의 구성에 따르면, 우리는 다음과 같이 액세스 할 수 있습니다 : http://127.0.0.1:8888/eureka-server/default/master
응용 프로그램 -> Eureka -Server (응용 프로그램 이름)
프로파일 -> 기본값 (활성화 구성, 일반적으로 접미사, 아래 설명)
레이블 -> 마스터 (지점)
방문 결과는 다음과 같습니다.
프로필이 더 중요합니다. 구성 파일을 읽는 것으로 이해할 수 있습니다. 둘 이상의 구성 파일이 있으면 다음이있을 수 있습니다.
Eureka-Server.Properties (일반 구성 파일이며 기본적으로로드됩니다),
Eureka-Server-Mysql.Properties,
Eureka-Server-Oracle.Properties,
Eureka-Server-JPA. -Properties,
Eureka-Server-Mysql.Properties ......
속성 구성 파일 중 일부를 선택적으로로드 할 수 있으므로 다음과 같이 쓸 수 있습니다.
이 시점에서 스프링 클라우드-콘피드 서버는 단순히 설정됩니다. 다음 장에서는 프로젝트에서 구성을 읽는 방법을 알려 드리겠습니다.
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.