准备工作
Eureka-client一个,Eureka-server一个,config-server一个
1.1 pom的准备
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency>
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency>
1.2 配置文件
eureka-client
server: port: 8081 spring: application: name: eureka-client1 eureka: instance: hostname: localhost prefer-ip-address: true client: service-url: default-zone: http://localhost:8761/eureka/
server: port: 8761 eureka: instance: hostname: localhost prefer-ip-address: true client: service-url: default-zone: http://${eureka.instance.hostname}:${server.port}/eureka/ register-with-eureka: false fetch-registry: false server: wait-time-in-ms-when-sync-empty: 0 enable-self-preservation: false
config-server
目录结构
server: port: 8888 spring: application: name: config-server profiles: active: native
server: port: 8081 spring: application: name: eureka-client1 eureka: client: service-url: default-zone: http://localhost:8761/eureka/
server: port: 8761 eureka: instance: hostname: localhost prefer-ip-address: true client: service-url: default-zone: http://localhost:8761/eureka/ register-with-eureka: true fetch-registry: true server: wait-time-in-ms-when-sync-empty: 0 enable-self-preservation: false
然后先后启动config-server、eureka-server、eureka-client