springboot整合mybatis bean注入失敗

異常報文: 

Field adminDAO in com......service.impl.AdminServiceImpl required a bean of type 'com.....dao.AdminDAO' that could not be found.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.5.RELEASE)

2019-05-25 23:39:27.645  INFO 31864 --- [           main] com.eszb.SprintbootdemoApplication       : Starting SprintbootdemoApplication on DESKTOP-6MD93CN with PID 31864 (D:\java\springboot-project\sprintbootdemo\target\classes started by Mr.Yu in D:\java\springboot-project\sprintbootdemo)
2019-05-25 23:39:27.649  INFO 31864 --- [           main] com.eszb.SprintbootdemoApplication       : No active profile set, falling back to default profiles: default
2019-05-25 23:39:28.523  INFO 31864 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-05-25 23:39:28.540  INFO 31864 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-05-25 23:39:28.540  INFO 31864 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.19]
2019-05-25 23:39:28.639  INFO 31864 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-05-25 23:39:28.639  INFO 31864 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 949 ms
2019-05-25 23:39:28.678  WARN 31864 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'adminController': Unsatisfied dependency expressed through field 'adminService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'adminService': Unsatisfied dependency expressed through field 'adminDAO'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.eszb.dao.AdminDAO' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2019-05-25 23:39:28.681  INFO 31864 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-05-25 23:39:28.692  INFO 31864 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-05-25 23:39:28.763 ERROR 31864 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Field adminDAO in com.eszb.service.impl.AdminServiceImpl required a bean of type 'com.eszb.dao.AdminDAO' 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.eszb.dao.AdminDAO' in your configuration.


Process finished with exit code 1

問題描述:這個異常描述是在service類裏面用到的dao層接口,在注入dao層接口的時候,出現了異常,沒有找到dao層的這個類,這個是由於spring沒有掃到dao層的接口的原因,所以需要在啓動的類上加上掃描dao層的類的註解,如下:

@MapperScan("com.eszb.dao")

此時就ok了

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