报错sqlSessionFactory「建议收藏」

2022-08-14 16:24:29 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

Exception encountered during context initialization – cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis-config.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 47; 文档根元素 “mapper” 必须匹配 DOCTYPE 根 “configuration”。

排查错误:

1.查看applicationContext.xml中的mybatis工厂配置:

发现没有网上所说的那些: <property name=”mapperLocations” value=”classpath*:com/zp/mall/mapper/*Mapper.xml”/>

与<mappers><mapper resource=” “/></mappers>重复扫描查询映射文件的错误

2.容易疏忽的问题ps:搞了半天难死小白了

Cause: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 47; 文档根元素 “mapper” 必须匹配 DOCTYPE 根 “configuration”。

一开始查看 我的mybatis-config.xml 与 mapper.xml都写了前三行的代码以为不是这里的问题

结果最后发现mybatis-config.xml 与Mapper.xml的前三行类似与注解的代码不一样

写Mapper.xml的时候偷懒复制的mybatis-config.xml上的就一直找不出来错误

Mybatis-config.xml:

<?xml version=“1.0” encoding=“UTF-8”?>

<!DOCTYPE configuration PUBLIC “-//mybatis.org//DTD Config 3.0//EN”

“http://mybatis.org/dtd/mybatis-3-config.dtd”>

Mapper.xml:

<?xml version=“1.0” encoding=“UTF-8”?>

<!DOCTYPE mapper PUBLIC “-//mybatis.org//DTD Mapper 3.0//EN”

“http://mybatis.org/dtd/mybatis-3-mapper.dtd”>

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/133522.html原文链接:https://javaforall.cn

0 人点赞