标签:界面 概述 package pre 文件 微信 value provider discovery
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency>
package com.miniooc.eurekafeign; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; /** * EurekaFeignApplication * 应用程序启动类,程序入口 * * @author 宋陆 * @version 1.0.0 */ @EnableDiscoveryClient // 激活 Eureka 服务发现配置 @EnableFeignClients // 激活 Feign 配置 @SpringBootApplication public class EurekaFeignApplication { public static void main(String[] args) { SpringApplication.run(EurekaFeignApplication.class, args); } }
package com.miniooc.eurekafeign.service; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RequestMapping; /** * EurekaFeignService * 服务消费服务类,调用服务提供者提供的服务,实现业务 * * @author 宋陆 * @version 1.0.0 */ @FeignClient(value = "eureka-provider") // 调用的微服务的名称 public interface EurekaFeignService { @RequestMapping(value = "/hello") String feignTest(); }
package com.miniooc.eurekafeign.controller; import com.miniooc.eurekafeign.service.EurekaFeignService; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; /** * EurekaFeignController * 服务消费控制器类,对用户提供服务 * * @author 宋陆 * @version 1.0.0 */ @RestController public class EurekaFeignController { @Resource private EurekaFeignService eurekaFeignService; @RequestMapping("/hello") public String hello() { String message = eurekaFeignService.feignTest(); System.out.println(message); return "获取到的信息:" + message; } }
server: port: 9529 spring: application: name: eureka-feign eureka: client: serviceUrl: defaultZone: http://localhost:9527/eureka/
微信号:songlu2011
标签:界面 概述 package pre 文件 微信 value provider discovery
原文地址:https://www.cnblogs.com/songlu/p/9934447.html