写了一个 Eureka 注册调用的 demo,代码大致如下:
Feign
@FeignClient(name = "spring-cloud-provider") public interface HelloRemote { @RequestMapping("/hello") public String hello(@RequestParam("name")String name); }
controller
@RestController public class HelloController { @Autowired HelloRemote helloRemote; @RequestMapping("/hello/{name}") public String index(@PathVariable("name") String name){ return helloRemote.hello(name); } }
程序启动时遇到:
*************************** APPLICATION FAILED TO START *************************** Description: Field helloRemote in com.freemud.controller.HelloController required a bean of type 'com.freemud.controller.HelloRemote' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true) Action: Consider defining a bean of type 'com.freemud.controller.HelloRemote' in your configuration.
报错大致的意思就是 HelloController 中 @Autowired 自动注入的属性 HelloRemote
无法被找到
解决:
问题应当出在 Feign 上,在写 @EnableFeignClients 注解的时候应当加上包名,否则就会出现读取不到的情况。
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于