③. 修改端口8001和80
- ①. pom.xml
<!--Eureka-client--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>
②. application.xml
eureka: client: #表示向注册中心注册自己 默认为true register-with-eureka: true #是否从EurekaServer抓取已有的注册信息,默认为true,单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡 fetch-registry: true service-url: #单机版:defaultZone: http://localhost:7001/eureka/ # 入驻地址 defaultZone: http://localhost:7001/eureka/ # 入驻地址
server: port: 8001 spring: application: name: cloud-payment-service datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: org.gjt.mm.mysql.Driver url: jdbc:mysql://localhost:3306/db2019?useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: root mybatis: mapperLocations: classpath:mapper/*.xml type-aliases-package: com.atguigu.springcloud.entities eureka: client: #表示向注册中心注册自己 默认为true register-with-eureka: true #是否从EurekaServer抓取已有的注册信息,默认为true,单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡 fetch-registry: true service-url: #单机版:defaultZone: http://localhost:7001/eureka/ # 入驻地址 defaultZone: http://localhost:7001/eureka/ # 入驻地址
③. 主启动类
@SpringBootApplication @EnableEurekaClient public class PaymentMain8001 { public static void main(String[] args) { SpringApplication.run(PaymentMain8001.class,args); } }
- ④. 80端口也是如下所示
- ⑤. 测试结果如下
④. Eureka集群
①. Eureka集群原理的说明
- ①. 互相注册、相互守望、对外暴露一个集体
- ②. 图示: