SpringCloud——Feign服务调用报错

写了一个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)