在用eclipse运行springboot+mybatis过程中报错信息:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'raceController': Unsatisfied dependency expressed through field 'raceService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'raceServiceImp': Unsatisfied dependency expressed through field 'raceDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'IRaceDao' defined in file [D:\STSworkspace\cms\target\classes\com\example\cms\dao\IRaceDao.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.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 16; 文档根元素 "configuration" 必须匹配 DOCTYPE 根 "mapper"。
解决方法:
我的目录结构是
是application.properties的mybatis配置出的问题
mybatis.type-aliases-package=com.example.cms.bean
mybatis.mapper-locations=classpath:com/example/cms/mapper
mybatis.config-location=classpath:mybatis-config.xml
只用加上面两条配置就好了,把location注释掉就能运行了
版权声明:本文为weixin_46255209原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。