Feign transmission attention
Recently, I have tried to refactor the previous project with SpringCloud and used Feign client components to call microservices. There are often problems that cannot pass parameters and become null. I checked online and found that there are still certain restrictions on the use of feign in parameters. The main thing is to pay attention to:
1. When the parameters are complex, feign will force the post request even if it is declared as a get request.
2. @GetMapping similar annotation declaration request is not supported. @RequestMapping(value = "url",method = ) is required.
3. When using @RequestParam annotation, you must add parameter names afterwards
I wrote a simple case, and simultaneously transmit an object and a string as request parameters, mainly focusing on the declaration of parameters. Please refer to the relevant knowledge about the dependencies and configurations of eureka and feign, such as the following information. For reference only:
Server side (producer)
@RestController
public class ItemController {
@Autowired
private ItemService itemService;
/**
* Add to
* @param item
* @param desc
* @return
*/
@RequestMapping("/item/save")
public Result addItem(@RequestBody Item item, @RequestParam("desc") String desc){
return (item, desc);
}
}
Client (consumer)
@FeignClient("item-service")
public interface ItemFeignClient {
/**
* Add to
* @param item
* @param desc
* @return
*/
@RequestMapping(value = "/item/save",method = )
Result addItem(@RequestBody TbItem item, @RequestParam("desc") String desc);