提交 2e908ce0 编写于 作者: S shenhongxi

springcloud feign

上级 c3507b41
......@@ -28,6 +28,11 @@
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<!--<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
......
......@@ -4,12 +4,14 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
/**
* Created by shenhongxi on 2017/9/14.
*/
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class ConsumerApplication {
......
package com.itlong.whatsmars.springcloud.consumer.controller;
import com.itlong.whatsmars.springcloud.consumer.feign.DemoFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -17,8 +18,16 @@ public class DemoController {
// @Value("${foo}")
// private String foo;
@Autowired
private DemoFeign demoFeign;
@RequestMapping("/hello")
public String hello(String name) {
return restTemplate.getForObject("http://demo-provider/hello?name=" + name, String.class);
}
@RequestMapping("/hi")
public String hi(String name) {
return demoFeign.hello(name);
}
}
package com.itlong.whatsmars.springcloud.consumer.feign;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* Created by shenhongxi on 2017/9/14.
*/
@FeignClient("demo-provider")
public interface DemoFeign {
@RequestMapping("/hello")
String hello(@RequestParam(name = "name") String name); // 此处必须有RequestParam
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册