问题背景
在springboot项目中加新的子module,配置完各个层和yml后,发现报了这个错,控制台完整报错是这样的
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
2022-04-15 21:38:20.318 INFO 12400 — [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2022-04-15 21:38:20.343 ERROR 12400 — [ restartedMain] o.s.boot.SpringApplication: Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘eduOrderController’:…
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eduOrderServiceImp
…Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
…Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method ‘sqlSessionFactory’ threw exception; nested exception is org.apache.ibatis.builder.BuilderExcept
…Caused by: org.xml.sax.SAXParseException: 不允许有匹配 “[xX][mM][lL]” 的处理指令目标
…
问题分析
首先检查了一遍各个注解和项目结构,感觉没什么问题,@service,@Controller,@Data都加了
去网上找,主要有以下几种
1, 没有加全注解,@Mapper,@Service这些都要加全,这个都没问题,确定和之前写的子项目没区别
2.然后看这个报错:Caused by: java.lang.IllegalArgumentException: Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required
网上讲这个其实就是springboot整合mybatis的一个bug
解决办法第一种;加注解,但这个我也加了
第二种就是数据源配置的问题,看看spring启动类里是不是有这句
这里是这句使得mybatis数据源配置无法完成,把括号和里面的东西全删掉
第三种就是前两种都不行的情况下,就要看这句报错…Caused by: org.xml.sax.SAXParseException: 不允许有匹配 “[xX][mM][lL]” 的处理指令目标
去mybatis-config.xml下一看
好家伙,写的太急,弄进去一堆空格
而在外面看
这里并不显示里面的报错,看来idea里的xml文件并不会将报错显示在外面,不打开还真发现不了,隐约记得myeclipse也是这样
,改了以后控制台不再报错
后续补充
之后又碰到这个问题,发现不是前几种,尝试重启电脑后好用了,想了一下,可能是nacos的服务问题,
在开启时是startup,但是关闭时直接关闭cmd窗口,应该运行shuidown.cmd
问题原因
主要就是数据源问题,高版本的spring不自动注入sqlSessionFactory,指定了mybatis,就要保证yml里配置正确