org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘vi

SpringBoot2+Mybatis+maven部署项目报错

初学SpringBoot2+Mybatis+maven部署项目时
Field videoMapper in com.xdclass.demo.service.impl.VideoServiceImpl required a bean of type ‘com.xdclass.demo.mapper.VideoMapper’ that could not be found.
发生这样的异常是因为没有在启动类上加上:@MapperScan(“com.xdclass.demo.mapper”)

其中@MapperScan中包名必须标注到mapper层

2021-02-01 21:32:26.480  WARN 268 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'videoController': Unsatisfied dependency expressed through field 'videoService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'videoServiceImpl': Unsatisfied dependency expressed through field 'videoMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.xdclass.demo.mapper.VideoMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2021-02-01 21:32:26.483  INFO 268 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-02-01 21:32:26.495  INFO 268 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-02-01 21:32:26.556 ERROR 268 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
***************************
APPLICATION FAILED TO START
***************************
Description:
Field videoMapper in com.xdclass.demo.service.impl.VideoServiceImpl required a bean of type 'com.xdclass.demo.mapper.VideoMapper' 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.xdclass.demo.mapper.VideoMapper' in your configuration.

添加后执行结果:

 .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::  (v2.3.9.BUILD-SNAPSHOT)

2021-02-01 22:05:15.176  INFO 13200 --- [           main] com.xdclass.demo.DemoApplication         : Starting DemoApplication on DESKTOP-CGIVCN0 with PID 13200 (E:\IDERdate\demo\target\classes started by Yang in E:\IDERdate\demo)
2021-02-01 22:05:15.178  INFO 13200 --- [           main] com.xdclass.demo.DemoApplication         : No active profile set, falling back to default profiles: default
2021-02-01 22:05:16.256  INFO 13200 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-02-01 22:05:16.274  INFO 13200 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-02-01 22:05:16.275  INFO 13200 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-02-01 22:05:16.376  INFO 13200 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-02-01 22:05:16.376  INFO 13200 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1149 ms
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
Parsed mapper file: 'file [E:\IDERdate\demo\target\classes\mapper\VideoMapper.xml]'
2021-02-01 22:05:16.682  INFO 13200 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-02-01 22:05:16.828  INFO 13200 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-02-01 22:05:16.837  INFO 13200 --- [           main] com.xdclass.demo.DemoApplication         : Started DemoApplication in 1.935 seconds (JVM running for 2.579)
2021-02-01 22:05:46.453  INFO 13200 --- [nio-8080-exec-4] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-02-01 22:05:46.454  INFO 13200 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2021-02-01 22:05:46.462  INFO 13200 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Completed initialization in 8 ms
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a30c534] was not registered for synchronization because synchronization is not active
2021-02-01 22:05:46.489  INFO 13200 --- [nio-8080-exec-4] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-02-01 22:05:46.705  INFO 13200 --- [nio-8080-exec-4] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
JDBC Connection [HikariProxyConnection@1160950493 wrapping com.mysql.cj.jdbc.ConnectionImpl@76738b64] will not be managed by Spring
==>  Preparing: select * from video
==> Parameters: 
<==    Columns: id, title, summary, cover_img, price, create_time, point
<==        Row: 30, 互联网架构之JAVA虚拟机JVM零基础到高级实战, https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/video/2019_backend/jvm_detail.jpeg, https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/xdclass_pro/video/2019_backend/jvm.jpeg, 3980, 2019-06-24 22:14:00, 9.1
<==        Row: 31, 权限框架Shiro+SpringBoot2.x零基础到高级实战, https://xd-video-pc-img.oss-cn-beijing.aliyuncs.com/x
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值