spring cloud 采坑记 (01)

spring cloud 神圣 3年前 (2018-02-05) 43438次浏览 717个评论

FeignClient接口

get方法获取路径中的变量需要

@FeignClient(“nuwa-user-service”)

public interface UserService {
@RequestMapping(value = “/user/{id}”, method = RequestMethod.GET)
public User findById(@PathVariable(“id”) Long id);

}

这种不行

@GetMapping(“/user/{id}”)

这种也不行

public User findById(@PathVariable Long id);

}

那么复杂的对象如何请求呢? /query-by?id=xxx&username=xxx

@FeignClient(“nuwa-user-service”)
public interface UserService {
@RequestMapping(value = “/query-by”, method = RequestMethod.GET)
public User queryBy(@RequestParam(“id”)Long id, @RequestParam(“username”)String username);

}

这种不行

@FeignClient(“nuwa-user-service”)
public interface UserService {
@RequestMapping(value = “/query-by”, method = RequestMethod.GET)
public User queryBy(@RequestParam(“id”)Long id, @RequestParam(“username”)String username);

}

发现项目启动后第一次请求总是500

网上找过这种问题发现是懒加载的问题

网上给出了三种解决方法

1.延长超时时间

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000

2.禁用超时时间

hystrix.command.default.execution.timeout.enabled: false

3.直接禁用hystrix

feign.hystrix.enabled: false

 

喜欢 (13)

您必须 登录 才能发表评论!