新手入門 ,關於string boot中的這個問題,搞了好久,現在終於解決了
報錯信息如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [D:\stringbootworkspace\cmmm\target\classes\com\xc\mjl\demo\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:\stringbootworkspace\cmmm\target\classes\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]" 的處理指令目標。
解決方案:可能有兩處出錯
第一處是配置文件中的
mybatis.type-aliases-package=com.xc.demo
此處必須和前面包名一致
第二處是寫sql的Mapper中的,這一個最不容易找,看起來一點錯都沒有,但是運行就報錯
<?xml version="1.0" encoding="UTF-8"?>
就是這個玩意一定要頂頭寫,一定一定不能空行,它就是第一行,它前面空行就會報錯,
嗯,大概就這樣了,希望有人看到這個錯對你有用,謝謝,最后還是要說一下新手第二條切記,不明顯,一不留心還容易出