【异常】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只有子孙包),原理参考另一博文

你可能感兴趣的:(#,SpringBoot,JAVA,srpingboot)