Requirements: in order to call customer service, check out the user information in the order in
order-service和user-service
1.user-service normally provided controller interfaces
/ ** The query user id User Information * @param * @return * / @RequestMapping (value = "/ {id}", Method = RequestMethod.GET) @ApiOperation (value = "The user id querying user information", notes = "The user id querying user information") public ResponseData getUserInfo (@PathVariable ( "id") Long id, @ RequestParam ( "userType") int userType) { return ResponseDataUtil.buildSuccess ( "200 is", "query is successful", userService .getUserInfoById (ID, userType)); }
2.user-service in the application, enabled feign client
@EnableDiscoveryClient @SpringBootApplication @EnableFeignClients @ComponentScan("com.****") public class TmsUserApplication { public static void main(String[] args) { SpringApplication.run(TmsUserApplication.class, args); } }
3.order-service api to write a definition of the interface, and user-service in the same way as the controller
/ ** * User Information * @description * @author Guo * @date 2019-10-31 * / @FeignClient (value = "User--Service", configuration = FeignConfiguration.class) configuration // here transmitted directly to the service header , user-service service name is the user public interface UserService { / ** * querying user information * @param * @return * / @RequestMapping (value = "/ API /. 1 / user / users / {ID}", Method = RequestMethod ... GET) public the Map <String, Object> getUserInfoById (@PathVariable ( "ID") ID Long, @RequestParam ( "userType") userType int); }
4.order-service in business methods, direct reference
@Autowired private UserService userService;userService.getUserInfoById(1,1);