Error creating bean with name 'xxxController’错误的一个解决思路
SpringBoot整合MyBatis时发生的一个错误,百度搜索这个错误地时候错误原因大多是使用mybatis-generator
时导致Mapper.xml中出现相同的id,但是我的几条sql语句都是手打的,也检查确认不存在id相同的情况。
虽然这个错误原因跟我不相符,但是基本能确定就是Mapper文件中出现问题。某一次调试时出错信息出现了类似**“不允许有匹配 “[xX][mM][lL]” 的处理指令目标。”**这个错,搜了一下结果是配置文件中
<?xml version="1.0" encoding="UTF-8" ?>
必须是xml文件中的第一个元素且前面不能空格!
改完之后果然不报错了,配置文件复制粘贴的时候要注意这些细节啊!
报错参考:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [D:\IDEAtest\springboot-data-mybatis\target\classes\com\joanna\springbootdatamybatis\mapper\UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\IDEAtest\springboot-data-mybatis\target\classes\mybatis\mapper\UserMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 6; 不允许有匹配 "[xX][mM][lL]" 的处理指令目标。
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:660) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.3.7.jar:5.3.7]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata