eureka服务注册与服务发现
1 eureka服务端编写
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
2 eureka客户端编写
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
application:
name: client
启动如果报错,需要引入spring-boot-starter-web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
3 eureka高可用
复制一个Application,改端口,一个8761,一个8762
-Dserver.port=8761
**分别启动EurekaApplication1 和 EurekaApplication2
EurekaApplication1 注册到8762
defaultZone: http://localhost:8762/eureka/
EurekaApplication2 注册到8761**
defaultZone: http://localhost:8761/eureka/
client端配置多个服务:
defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/
同理,三个服务