<!-- feign --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency>
新增AI编程课程,引领技术教育新趋势
<!-- feign --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency>
配置文件
对日期的解析,消费者要跟提供者一致,不然会报json解析错误
#超时时间feign.httpclient.connection-timeout=30000#mvc接收参数时对日期进行格式化spring.mvc.date-format=yyyy-MM-dd HH:mm:ss #jackson对响应回去的日期参数进行格式化spring.jackson.date-format=yyyy-MM-dd HH:mm:ss spring.jackson.time-zone=GMT+8
服务调用
1、springdatejpa 应用名称,是服务提供者在eureka注册的名字,Feign会从注册中心获取实例
2、如果不想启动eureka服务,直连本地开发:@FeignClient(name = "springdatejpa", path = "/user/",url = "http://localhost:10086")
3、如果使用@RequestMapping,最好指定调用方式
4、消费者的返回值必须与提供者的返回值一致,参数对象也要一致
更多@FeignClient注解参数配置,请参阅官方文档
@FeignClient(name = "springdatejpa", path = "/user/") public interface MyspringbootFeign { @RequestMapping(value = "get/{id}") Result<UserVo> get(@PathVariable("id") Integer id); @RequestMapping(value = "list", method = RequestMethod.GET) Result<List<UserVo>> list(@RequestBody UserVo entityVo); }
/** * controller调用 */ @GetMapping("feign/list") Result<List<UserVo>> list(UserVo userVo){ return myspringbootFeign.list(userVo); }
启动类