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文件中添加

       
           org.mybatis.spring.boot
           mybatis-spring-boot-starter
           2.1.0
       

解决问题

你可能感兴趣的:(spring,boot,mybatis,开发错误集锦)