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註解的時候應當加上包名,否則就會出現讀取不到的情況。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章