欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SpringCloud——Feign服务调用报错

程序员文章站 2022-04-26 10:31:36
...

写了一个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注解的时候应当加上包名,否则就会出现读取不到的情况。

相关标签: SpringCloud