java springboot interface to forward references openfeign

1, build.gradle introduced assembly

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 startup class annotate @EnableFeignClients

3, add an interface

url in configuration item, or you can write directly to die for example: http://hhh.com

@Service

@FeignClient(value = "TestApiService", url = "${test.serverUrl}")

public interface TestApiService {

/**

  • PostMapping the value is to be forwarded address

  • @param stop

  • @return

    */

@PostMapping(value = "/api/v1/user/role")

CommonResponse<Object> userRole(@RequestBody UserRoleParam param);

}

4, you can call the Controller

@Autowired

private TestApiService testApiService;

/**

  • @return

    */

@PostMapping(value = "/v1/user/role/")

public CommonResponse<Object> userRole(@RequestBody UserRoleParam param) {

return testApiService.userRole(param);

}

This allows the interface to forward

Guess you like

Origin blog.51cto.com/jinliang/2477496