引入feign
<!--使用feign-->
<!--<dependency>-->
<!--<groupId>org.springframework.cloud</groupId>-->
<!--<artifactId>spring-cloud-starter-feign</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.0.0.M3</version>
</dependency>
我的是因为spring boot 的版本是2.0.0.M3所以需要使用下面的应用
然后,使用。有俩个项目product和order,现在是在order中调用product的’/msg’方法。所以在order项目中,新建ProductClient.java
@FeignClient(name="product")
public interface ProductClient {
@RequestMapping("/msg")
String productMsg();
}
使用,在order中的控制类
@Autowired
private ProductClient productClient;
//使用
String response = productClient.productMsg();