【异常】expected at least 1 bean which qualifies as autowire candidate for this depende

springboot初学者经常会出现下面的问题,expected at least 1 bean which qualifies as autowire candidate for this depende

2020-10-16 10:44:50.481 INFO 5404 — [ main] com.rest.app.ServletInitializer : Starting ServletInitializer v0.0.1-SNAPSHOT on DESKTOP-FK1JUDF with PID 5404 (C:\Users\DCR\eclipse-workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\IMworkflowRestApi\WEB-INF\classes started by DCR in C:\Users\DCR\eclipse\jee-2020-09\eclipse)
2020-10-16 10:44:50.506 INFO 5404 — [ main] com.rest.app.ServletInitializer : No active profile set, falling back to default profiles: default
2020-10-16 10:44:57.312 WARN 5404 — [ main] o.m.s.mapper.ClassPathMapperScanner : No MyBatis mapper was found in ‘[com.rest.app]’ package. Please check your configuration.
2020-10-16 10:44:57.948 INFO 5404 — [ main] o.a.c.c.C.[Catalina].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-10-16 10:44:57.949 INFO 5404 — [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 6955 ms
2020-10-16 10:45:01.796 WARN 5404 — [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘personalController’: Unsatisfied dependency expressed through field ‘jasperService’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.rest.domain.service.shared.util.JasperService’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2020-10-16 10:45:01.828 INFO 5404 — [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2020-10-16 10:45:02.349 ERROR 5404 — [ main] o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:

Field jasperService in com.rest.app.PersonalController required a >bean of type ‘com.rest.domain.service.shared.util.JasperService’ >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.rest.domain.service.shared.util.JasperService’ in your >configuration.

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.catalina.loader.WebappClassLoaderBase (file:/C:/apache-tomcat-9.0.38-windows-x64/apache-tomcat-9.0.38/lib/catalina.jar) to field java.io.ObjectStreamClass$Caches.localDescs
WARNING: Please consider reporting this to the maintainers of org.apache.catalina.loader.WebappClassLoaderBase
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

这个是因为无法注入导致的,出现这个问题需要检查下面几个问题

  1. 查看接口实现类是否加入注解,如service、repository等,因为只有加入这些注解spring容器才会接管来自动装配
  2. 注入的类是否在application的同级包或者子孙包下面,因为2.X以后只有同级包或者子孙包才可以扫描到(1.X只有子孙包),原理参考另一博文
  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
引用中提到了一个错误信息,它指示在自动注入依赖时找不到符合条件的bean。类似的错误信息在引用中也有提到。原因可能是重复注入相同的bean接口类。解决这个问题的方法有两种,一种是去掉重复的注解,另一种是去掉重复的接口注解或类注解。 另外,引用中提到了另一种可能的情况,即自动注入失败。在测试类中遇到了这个问题,实际上自动注入的是FeginClient而不是Service。通过将@Autowired的required属性设置为false可以解决这个问题。 总结起来,这些引用内容提供了一些关于自动注入依赖时出现问题的可能原因和解决方法。你可能需要检查重复注解和依赖的类型,以确保正确地注入bean。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [expected at least 1 bean which qualifies as autowire candidate for this dependency.](https://blog.csdn.net/weixin_42190471/article/details/117827289)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations](https://blog.csdn.net/qinjiangcai/article/details/125880816)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

加班狂魔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值