工程架构
复制mscloud-provider模块变成 mscloud-provider8004
新增eureka-client的依赖
完整代码
junit junit 4.13 test org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-actuator org.mybatis.spring.boot mybatis-spring-boot-starter com.alibaba druid-spring-boot-starter 1.1.10 mysql mysql-connector-java org.springframework.boot spring-boot-starter-jdbc org.springframework.boot spring-boot-devtools runtime true org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test
完整配置
eureka:client:#表示是否将自己注册进EurekaServer默认为true。register-with-eureka: true#是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡fetchRegistry: trueservice-url:#单机版defaultZone: http://localhost:8003/eureka/# 集群版#defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eurekainstance:instance-id: provider8004#访问路径可以显示IP地址prefer-ip-address: true#Eureka客户端向服务端发送心跳的时间间隔,单位为秒(默认是30秒)#lease-renewal-interval-in-seconds: 1#Eureka服务端在收到最后一次心跳后等待时间上限,单位为秒(默认是90秒),超时将剔除服务#lease-expiration-duration-in-seconds: 2
1.先启动eurekaserver,
然后启动eurekaclient
查看效果:
1.pom文件
org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-actuator org.springframework.boot spring-boot-devtools runtime true org.projectlombok lombok true org.springframework.boot spring-boot-starter-test test
2.yml配置
eureka:client:#表示是否将自己注册进EurekaServer默认为true。register-with-eureka: true#是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡fetchRegistry: trueservice-url:#单机defaultZone: http://localhost:8003/eureka
3.启动类
4.结果
http://localhost:8005/consumer/payment/create?itemName=橘子&price=45
http://localhost:8005/consumer/payment/get/2