一、feign参数传递
1、 不支持@GetMapping类似注解声明请求,需使用@RequestMapping(value = “url”,method = RequestMethod.GET)
2、当参数比较复杂时,feign即使声明为get请求也会强行使用post请求,解决方推荐第4项
3、使用@RequestParam注解时必须要在后面加上参数名;feign 客户端的配置,包含
熔断、调用服务名称,url 或日志等信息
4、案例
@FeignClient(name ="API-SERVICE",fallbackFactory = FeignFallBack.class )
public interface FeignService {
/***
* @methodName feign 多参数接口请求
* @Description: 查询船图信息
**/
@RequestMapping(value = "/demo/list", method = RequestMethod.GET)
public ok<?> list(@RequestParam("name") String name, @RequestParam("sex") String sex, @RequestParam("address") String address, @RequestParam("telphone") String telphone, @RequestParam("pcgod") String pcgod);
/***
* TODO: feign 传递对象进行get请求
* @methodName
*/
@RequestMapping(value = "/demo/listByObject", method = RequestMethod.GET)
public ok<?> list(@SpringQueryMap DemoVo demoVo );
}
二、异常
`The injection point has the following annotations: - @org.springframework.beans.factory.annotation.The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)`
调用方配置 @EnableFeignClients指定clients
@EnableEurekaClient
@EnableAsync
@EnableCircuitBreaker
@SpringBootApplication(scanBasePackages="com.port")
@EnableFeignClients(clients = {FeignService.class})
@EnableHystrixDashboard
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
在调用方扫描feignClient 所在包
@EnableFeignClients(basePackages = {"com.gjtdport.*.api"})
@EnableEurekaClient
@EnableAsync
@EnableCircuitBreaker
@SpringBootApplication(scanBasePackages="com.gjtdport")
@EnableFeignClients(basePackages = {"com.gjtdport.*.api"})
@EnableHystrixDashboard
public class XxApplication {
public static void main(String[] args) {
SpringApplication.run(XxApplication.class, args);
}
}
二、建议同一微服务提供的feign 服务在同一接口中提供,规避 feignClient name 相同导致bean 重复定义问题