异常信息
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean
with name ‘sqlSessionFactoryBean’ defined in class path resource [bean-db.xml]:
Invocation of init method failed; nested exception is
org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause:
org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 134; 文档根元素 “beans” 必须匹
配 DOCTYPE 根 “null”。
如果你也是像我一样spring配置文件中在创建SqlSessionFactoryBean
的bean对象的话,那么大概率是指定mybatis-config全局配置文件写错了
<!-- sqlSessionFactory配置 -->
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:bean-db.xml"></property>
<property name="mapperLocations" value="classpath*:mapper/*Mapper.xml"></property>
<property name="typeAliasesPackage" value="com.wjw.pojo"></property>
</bean>
<property name="configLocation" value="classpath:bean-db.xml"></property>
这里配置配错了,比如我就不小心搞混了bean-db.xml和mybatis的配置文件。
原因及解决
指定的mybatis-config.xml
配置文件错误,修改正确的配置文件就好了