记一次Feign中实现传实体Bean的问题
时间:2022-08-25 10:22:40|栏目:JAVA代码|点击: 次
Feign如何传实体Bean
需要加一个@RequestBody序列化对象
/** * 新增 */ @PostMapping("saveOrder") @ResponseBody public void saveOrder(@RequestBody OrderBean orderBean) { userService.saveOrder(orderBean); }
接口接收请求也要加一个@RequestBody注解
/** * 新增 * @param orderBean */ @PostMapping("saveOrder") public void saveOrder(@RequestBody OrderBean orderBean);
Feign注入Bean为null,启动报错
主要是feign版本和swagger版本冲突,本项目spring cloud 版本为 Finchley.M8
swagger冲突版本
<!-- swagger2 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.2.2</version> </dependency>
解决方案
<!-- swagger2 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.5.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.5.0</version> </dependency>
feign Service案例
@FeignClient(name = "service-weixin",fallback = OAuthServiceFallBack.class, configuration = FeignConfig.class) public interface OAuthService { @RequestMapping(value = "/oauth/getOauth2AuthorizationUrl", method = RequestMethod.GET) ResultBean<String> getOauth2AuthorizationUrl(@RequestParam("url")String url); }
controller注入
@RestController @RequestMapping("/ticket") public class TicketController { @Autowired private TicketService ticketService; @Autowired private OAuthService oAuthService; ...
上一篇:Java 多线程之间共享数据
栏 目:JAVA代码
下一篇:IntelliJ IDEA 2020.3.3现已发布!新增“受信任项目”功能
本文地址:http://www.codeinn.net/misctech/211815.html