上传配置文件到GitHub
配置文件名为:eureka_config.yml,上传到GitHub的microservice-config库中,内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| spring: profiles: active: - dev --- server: port: 2004 context-path: / spring: profiles: dev eureka: instance: hostname: localhost client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ --- server: port: 2004 context-path: / spring: profiles: test eureka: instance: hostname: localhost client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
|
整合过程
引入依赖
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency>
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency>
<dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency>
|
application.yml配置
1 2 3
| spring: application: name: microservice-eureka-server-config
|
bootstrap.yml配置
1 2 3 4 5 6 7 8 9
| spring: application: name: microservice-eureka-server-config cloud: config: name: eureka_config uri: http://configserver.ledao.com:4001 profile: dev label: master
|
启动类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| package com.ledao;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer @SpringBootApplication public class EurekaApplication_2004 {
public static void main(String[] args) { SpringApplication.run(EurekaApplication_2004.class, args); } }
|
添加本地域名映射
找到 C:\Windows\System32\drivers\etc 打开hosts,底部加配置:
1
| 127.0.0.1 eureka2004.ledao.com
|
测试
启动项目:microservice-config-server-4001和microservice-eureka-server-config-2004
地址栏输入:http://eureka2004.ledao.com:2004/ ,如果配置成功会看到Eureka界面
PS.
整合提供者服务和消费者服务的过程也基本相似