服务提供者:
只是简单的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") //被调用接口的请求类型
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);
}
}
服务调用者:
<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);
}
}
启动服务调用者 和 启动服务提供者
请求:localhost:8002/helloTest
返回:hello
网友评论