单机模拟配置Eureka集群 (4)

application.yml配置文件

server: port: 8083 eureka: client: fetch-registry: true register-with-eureka: true serviceUrl: defaultZone: :8081/eureka/ instance: prefer-ip-address: true ip-address: 127.0.0.1 spring: application: name: service02 feign: client: default-config: connectTimeout: 10000 readTimeout: 10000

主程序

package com.linkanyway.service02; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; /** * @author linkanyway */ @EnableDiscoveryClient @EnableFeignClients @SpringBootApplication public class Service02Application { public static void main(String[] args) { SpringApplication.run (Service02Application.class, args); } }

服务调用的feign定义

package com.linkanyway.service02.feign; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.RequestMapping; /** * @author linkanyway * @version 1.0 * @name Service01 * @description TODO * @date 2021/02/01 20:31 */ @FeignClient("service01") public interface Service01 { /** * get * @return */ @RequestMapping("service/get") String get(); }

控制器代码

package com.linkanyway.service02.controller; import com.linkanyway.service02.feign.Service01; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @author linkanyway * @version 1.0 * @name ServiceController * @description TODO * @date 2021/02/01 20:34 */ @RestController @RequestMapping("service") public class ServiceController { final Service01 service01; public ServiceController(Service01 service01) { this.service01 = service01; } @RequestMapping("get") public String get() { return service01.get (); } }

启动service01,02

可以看到成功注册到注册中心

单机模拟配置Eureka集群

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsfxzx.html