🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
步骤如下: **1. 架构设计** ![](https://img.kancloud.cn/35/1c/351cbf5be5d98520c7e2fd8fb01c8ca6_1102x629.jpg) **2. 构建两个服务端模块**(我这里就不构建3个模块了,只构建2个模块) 两个服务端模块我已经提前构建好了,并将它们都注册到了Eureka集群中,模块名如下: ``` cloud-provider-payment8001 cloud-provider-payment8002 ``` **3. 两个模块的`resources/application.yml`配置** (1)模块 cloud-provider-payment8001 的配置。 ```yml server: port: 8001 spring: application: name: cloud-payment-service eureka: client: service-url: #将当前模块注册到eureka集群中 defaultZone: http://www.eureka7001.com:7001/eureka/,http://www.eureka7002.com:7002/eureka/,http://www.eureka7003.com:7003/eureka/ instance: instance-id: ${project.artifactId} prefer-ip-address: true lease-renewal-interval-in-seconds: 1 lease-expiration-duration-in-seconds: 2 ####actuator#### info: app.name: ${spring.application.name} company.name: www.atguigu.com build.artifactId: ${project.artifactId} build.version: ${project.version} ``` (2)模块 cloud-provider-payment8002 的配置。 ```yml server: port: 8002 spring: application: name: cloud-payment-service eureka: client: service-url: #将当前模块注册到eureka集群中 defaultZone: http://www.eureka7001.com:7001/eureka/,http://www.eureka7002.com:7002/eureka/,http://www.eureka7003.com:7003/eureka/ instance: instance-id: ${project.artifactId} prefer-ip-address: true lease-renewal-interval-in-seconds: 1 lease-expiration-duration-in-seconds: 2 ####actuator#### info: app.name: ${spring.application.name} company.name: www.atguigu.com build.artifactId: ${project.artifactId} build.version: ${project.version} ``` **4. 两个模块的controller代码一样,如下** ```java @RestController @RequestMapping("/payment") public class PaymentController { @Value("${server.port}") private String serverPort; @Value("${info.build.artifactId}") private String instanceId; @GetMapping("/idport") public String idPort() { return "instanceId:" + instanceId + ",serverPort:" + serverPort; } } ``` **5. 验证是否构建成功** 分别启动这两个服务端模块,然后分别访问得到如下信息说明构建成功了。 :-: http://localhost:8001/payment/idport ``` instanceId:cloud-provider-payment8001,serverPort:8001 ``` :-: http://localhost:8002/payment/idport ``` instanceId:cloud-provider-payment8002,serverPort:8002 ```