服務(wù)提供者:
只是簡單的boot火惊,沒有使用Cloud
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
代碼:
@FeignClient(name = "demo")
public interface HelloClient {
@GetMapping("/hello") //被調(diào)用接口的請求類型
String test();
}
@RestController
public class TestController {
@GetMapping("/hello")
public String test(HttpServerRequest request){
return "hello";
}
}
@SpringBootApplication
@EnableFeignClients
public class FeignApp8009 {
public static void main(String[] args) {
SpringApplication.run(FeignApp8009.class);
}
}
服務(wù)調(diào)用者:
<dependency>
<groupId>com.spring.boot</groupId>
<artifactId>Boot-Feign</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
@Autowired
HelloClient helloClient;
@GetMapping("/helloTest")
public String feign(){
String test = helloClient.test();
return test;
}
@SpringBootApplication
public class Thymeleaf8005 {
public static void main(String[] args) {
SpringApplication.run(Thymeleaf8005.class, args);
}
}
啟動服務(wù)調(diào)用者 和 啟動服務(wù)提供者
請求:localhost:8002/helloTest
返回:hello