Commit 0793034b authored by XCQi's avatar XCQi

实现Feign远程调用后台接口功能

通过serviceId自动查询erueka中注册的服务列表并负载均衡调用
parent cf967f6b
Pipeline #46 canceled with stages
......@@ -2,8 +2,12 @@ package com.yingxin.springcloudconsumer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
public class SpringCloudConsumerApplication {
public static void main(String[] args) {
......
package com.yingxin.springcloudconsumer.controller;
import com.yingxin.springcloudconsumer.service.HelloService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class RestApi {
private final HelloService helloService;
public RestApi(HelloService helloService) {
this.helloService = helloService;
}
@GetMapping("/consumer")
public String helloConsumer() {
return helloService.hello();
}
}
package com.yingxin.springcloudconsumer.service;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
@FeignClient("spring-cloud-server-HelloWorld")
public interface HelloService {
@GetMapping("hello")
String hello();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment