标签:com auto config autowired ISE use ring inter -o
1、build.gradle中引入组件compile ("org.springframework.cloud:spring-cloud-starter-config:2.1.1.RELEASE")
compile ("org.springframework.cloud:spring-cloud-starter-openfeign:2.1.3.RELEASE")
2、Application启动类中添加注解@EnableFeignClients
3、添加 接口
url 在配置项中,也可以直接写死例如: http://hhh.com
@Service
@FeignClient(value = "TestApiService", url = "${test.serverUrl}")
public interface TestApiService {
/**
PostMapping中的value就是要转发的地址
@param param
@return
*/
@PostMapping(value = "/api/v1/user/role")
CommonResponse<Object> userRole(@RequestBody UserRoleParam param);
}
4、在Controller中调用即可
@Autowired
private TestApiService testApiService;
/**
@return
*/
@PostMapping(value = "/v1/user/role/")
public CommonResponse<Object> userRole(@RequestBody UserRoleParam param) {
return testApiService.userRole(param);
}
这样可以实现接口转发
java springboot 引用openfeign 接口转发
标签:com auto config autowired ISE use ring inter -o
原文地址:https://blog.51cto.com/jinliang/2477496