Spring Could Fegin UnsatisfiedDependencyException

被调用方

使用feign定义了一个接口

@FeignClient(name = "w-article-service", fallback = ArticleCategoryServiceHystrix.class)
public interface ArticleCategoryRemoteService {

    @RequestMapping(path = "/articleCate", method = RequestMethod.POST)
    WResult save(ArticleCategory articleCategory);
}

调用方

调用方调用被调用方的一个接口

@RequestMapping("/cate/")
@Controller
@Slf4j
public class ArticleCategoryController extends BaseController{

    @Autowired
    private ArticleCategoryRemoteService articleCategoryRemoteService;

    @ResponseBody
    @RequestMapping(path = "page", method = RequestMethod.GET)
    public WResponses page(@RequestParam Map<String, Object> params){
        try {
            WResult wResult = articleCategoryRemoteService.pages(
                    ParamAdapter.param2CategoryQueryParam(params),
                    ParamAdapter.start(params), ParamAdapter.limit(params));
            if (wResult.getCode() == ServiceRespCode.SUCCESS.code()) {
                return WResponses.ok().put("page", wResult.getData());
            }
            return WResponses.error(wResult.getCode(), wResult.getMsg());
        }catch (Exception e){
            log.error("query article category cause error!", e);
        }
        return WResponses.error("速将错误反馈给程序猿!");
    }
}

启动工程

@EnableHystrix
@EnableDiscoveryClient
@EnableFeignClients
@ComponentScan(basePackages = {"com.urwoo"})
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
@Slf4j
public class WSiteManagerApp {

    public static void main( String[] args ) {
        log.info("=================start WSiteManagerApp ...=================\n");
        SpringApplication.run(WSiteManagerApp.class, args);
        log.info("=================end WSiteManagerApp ...=================\n");
    }
}

出现问题

2018-01-11 00:36:30 [WARN] [restartedMain] [org.springframework.context.support.AbstractApplicationContext:551] - Exception 

encountered during context initialization - cancelling refresh attempt: 

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'articleCategoryController': 

Unsatisfied dependency expressed through field 'articleCategoryRemoteService'; nested exception is 

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 

'com.urwoo.article.ArticleCategoryRemoteService' available: expected at least 1 bean which qualifies as autowire candidate. 

Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2018-01-11 00:36:30 [INFO] [restartedMain] 

[org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer:101] - 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-01-11 00:36:30 [ERROR] [restartedMain] [org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter:42] - 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field articleCategoryRemoteService in com.urwoo.manager.controller.ArticleCategoryController required a bean of type 

'com.urwoo.article.ArticleCategoryRemoteService' that could not be found.


Action:

Consider defining a bean of type 'com.urwoo.article.ArticleCategoryRemoteService' in your configuration.

Disconnected from the target VM, address: '127.0.0.1:54589', transport: 'socket'

Process finished with exit code 0

解决方案

在启动类的@EnableFeignClients注解上新增(basePackages = {"com.urwoo"})

@EnableHystrix
@EnableDiscoveryClient
@EnableFeignClients(basePackages = {"com.urwoo"})
@ComponentScan(basePackages = {"com.urwoo"})
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
@Slf4j
public class WSiteManagerApp {

    public static void main( String[] args ) {
        log.info("=================start WSiteManagerApp ...=================\n");
        SpringApplication.run(WSiteManagerApp.class, args);
        log.info("=================end WSiteManagerApp ...=================\n");
    }
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,060评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,066评论 25 709
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,130评论 6 342
  • 最近书荒,暂时没有什么想看的书,便打算刷旧书。大学时买的一本小说《岛》成了我的首选。 提到《岛》,很多人第一个想到...
    古小也阅读 2,622评论 0 0
  • 文/ 檐铃化语 01 周末,朋友给我讲了一个发生在他身上令人啼笑皆非的故事。 M是大学里睡在朋友上铺的兄弟。两个人...
    檐铃化语阅读 4,320评论 0 11

友情链接更多精彩内容