eureka服务之间调用(3)

配置pom.xml

org.springframework.cloud spring-cloud-starter-eureka 1.2.7.RELEASE org.springframework.cloud spring-cloud-starter-feign 1.2.7.RELEASE org.springframework.boot spring-boot-starter-web spring-milestones Spring Milestones http://repo.spring.io/milestonefalse spring-milestones Spring Milestones http://repo.spring.io/milestonefalse org.springframework.boot spring-boot-maven-plugin

配置properties
server: port: 8763 spring: application: name: service-two这是发布至注册中心的服务名,靠此服务名服务之间相互调用 eureka: client: serviceUrl: defaultZone: http://127.0.0.1:8761/eureka配置注册中心地址

配置启动类
/** * 启动类 * @author WangD * */ @EnableDiscoveryClient//通过注解@EnableDiscoveryClient 表明自己是一个eurekaclient.去服务中心注册 @EnableFeignClients(basePackages="com.eureka.service")//去注册中心调用服务扫描包范围 @SpringBootApplication(scanBasePackages="com.eureka") public class CloudApplication2 { /** 启动 */ public static void main(String[] args) { SpringApplication.run(CloudApplication2.class, args); }}

编写调用其他服务service接口
@FeignClient("service-hi") //调用其服务的服务名即上一条博客(2) public interface SchedualService { @RequestMapping(value="https://www.it610.com/hi",method=RequestMethod.POST) public String gethi(); }

编写controller 调用器service接口调用其他服务
@RestController public class CloudClient { @Autowired private SchedualService schedualService; @RequestMapping("/testhi") public String cloudOne(){ return schedualService.gethi(); }

【eureka服务之间调用(3)】eureka服务之间调用(3)
文章图片

    推荐阅读