spring boot + mybatis报错:Error creating bean with name ‘***’ defined in file

报错日志

  • 警告部分
2019-07-24 17:23:23.394  WARN 10620 --- [           main]
ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginFilter': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'sysUserDao'; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sysUserDao' defined in file
[F:\workspace\13_micro-service\MicroServiceFramework\cetc-bdri-generic-manage-gateway\target\classes\com\cetc\manage\gateway\dao\SysUserDao.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
  • 报错部分
 java.net.Inet6AddressImpl.getHostByAddr(Native Method)
 java.net.InetAddress$2.getHostByAddr(InetAddress.java:933)
 java.net.InetAddress.getHostFromNameService(InetAddress.java:618)
 java.net.InetAddress.getHostName(InetAddress.java:560)
 java.net.InetAddress.getHostName(InetAddress.java:532)
 org.springframework.cloud.commons.util.InetUtils$$Lambda$101/865059288.call(Unknown Source)
 java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
 java.util.concurrent.FutureTask.run(FutureTask.java)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 java.lang.Thread.run(Thread.java:748)
2019-07-24 17:23:23.437  WARN 10620 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase       : The web application [api] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
2019-07-24 17:23:23.438  WARN 10620 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase       : The web application [api] appears to have started a thread named [RxIoScheduler-1 (Evictor)] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
 java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 java.lang.Thread.run(Thread.java:748)

分析

看第一眼,感觉是没有找到sysUserDao,这种解决方案对于spring boot来说,有如下解决方案:

  • 在启动类中添加 @ComponentScan(basePackages = {"com.***.***.****"}) 标签,com.***.***.****sysUserDao所在路径,由于springboot启动类会默认扫描启动类下所有的package,所以出现这种情况应该有两个:

1.自定义了@ComponentScan标签,没有定义扫描自己工程下的包
2.将自己的dao层放在了其他路径
对于以上两种情况,可以通过@ComponentScan注解来解决问题,但是对于我,没有解决问题

随后去检查mybatisspring boot的依赖,发现了问题,少引入了 mybatis-spring-boot-starter依赖,在pom文件中添加

       <dependency>
           <groupId>org.mybatis.spring.boot</groupId>
           <artifactId>mybatis-spring-boot-starter</artifactId>
           <version>2.1.0</version>
       </dependency>

解决问题

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值