1.配置中心配置
--啟動類
@SpringBootApplication
@EnableEurekaClient//注冊中心客戶端
@EnableConfigServer//配置服務端
public class ConfigApplication1299 {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication1299.class);
}
}
--application.yml
server:
port: 1299
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka
instance:
prefer-ip-address: true
spring:
application:
name: aigou-config-server
cloud:
config:
server:
git:
uri: https://github.com/db2king/aigou_config_application.git #github上的倉庫地址
username: yyy
password: xxx
--導包
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!--eureka客戶端-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--配置中心支持-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
2.服務提供者配置
--啟動類
@SpringBootApplication//標識為springcloud項目
@EnableEurekaClient//eureka的客戶端
public class PlatApplication8001 {
public static void main(String[] args) {
SpringApplication.run(PlatApplication8001.class);
}
}
--bootstrap.yml
spring:
cloud:
config:
uri: http://127.0.0.1:1299 #配置服務器
label: master #分支
name: plat-provider-application #github上面名稱
profile: test #環境
3.將服務提供者的配置文件配置到github中
| spring: | |
| profiles: | |
| active: dev | |
| --- | |
| server: | |
| port: 8001 | |
| spring: | |
| application: | |
| name: AIGOU-PLAT #不要使用下划線 | |
| profiles: dev | |
| eureka: | |
| client: | |
| service-url: | |
| defaultZone: http://localhost:7001/eureka #告訴服務提供者要把服務注冊到哪兒,注冊中心的地址 | |
| --- | |
| server: | |
| port: 8002 | |
| spring: | |
| application: | |
| name: AIGOU-PLAT-test #不要使用下划線 | |
| profiles: test | |
| eureka: | |
| client: | |
| service-url: | |
| defaultZone: http://localhost:7001/eureka #告訴服務提供者要把服務注冊到哪兒,注冊中心的地址 |
注意事項
配置中心配置文件的url地址是github倉庫地址
服務者配置文件中的name是github中yml的配置文件名字
