首先创建EurekaServer项目(我用springboot创建的)
第一步,导包
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
3.1.1
第二步,配置
server:
port: 7001
#eureka的配置
eureka:
instance:
hostname: localhost #eureka服务端实例名字
client:
#false表示不向注册中心注册自己
register-with-eureka: false
#false表示自己端就是注册中心,我的职责就是维护服务实例,不需要检索服务
fetch-registry: false
service-url:
#设置Eureka Server交互地址查询服务和注册服务都需要依赖这个地址
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
第三步,运行类注解
@SpringBootApplication
@EnableEurekaServer
public class CloudEurekaServer7001Application {
public static void main(String[] args) {
SpringApplication.run(CloudEurekaServer7001Application.class, args);
}
}
第四步,运行(在url上输入:localhost:7001)
其次,创建Eurekaclient端项目
第一步,导包
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
3.1.1
第二步,配置
eureka:
client:
#表示是否将自己注册到EurekaServer 默认true
register-with-eureka: true
#是否从EurekaServer抓取自己的注册信息,默认是true。单节点无所谓,集群必须设置true才能配合ribbon使用负载均衡
fetch-registry: true
service-url:
#入住地址
defaultZone: http://localhost:7001/eureka
第三步,运行类注解
@SpringBootApplication
@EnableEurekaClient
public class CloudPaymentServer8001Application {
public static void main(String[] args) {
SpringApplication.run(CloudPaymentServer8001Application.class, args);
}
}
第四步,运行(在url上输入:localhost:7001)
注意:1、application的名字是与你配置文件中spring.application.name名字一一对应的
2、要先运行eurekaServer后再运行client



