整合Spring和Mybatis 中org.springframework.beans.factory.BeanCreationException错误
来源:互联网 发布:mac解压不了zip 编辑:程序博客网 时间:2024/05/01 21:15
这两天学习strut2和spring的整合,启动服务器后总是爆粗如下错误,
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sqlSessionFactory' defined in URL [file:/E:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/StrutsTest/WEB-INF/classes/applicationContext.xml]:
Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException:Document root element "mapper", must match DOCTYPE root "configuration".
网上有如下解答:
---------------------------------------------------------------------------------------------------------------------------------------
Document root element "mapper", must match DOCTYPE root "configuration"
后来才发现,原来是xml文件的!doctype定义写错了。
mybatis.xml和mapper.xml都用了一个doctype
原来不是这样的。
mybatis.xml:
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
mapper.xml
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-----------------------------------------------------------------------------------------------------------------------------------------
applicationContext.xml 示例如下
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <bean id="firstAction" class="com.hoperun.action.FirstAction" scope="prototype"> <property name="live" ref="live"/> </bean> <bean id="ajaxAction" class="com.hoperun.action.AjaxAction" scope="prototype"></bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver"></property><property name="url" value="jdbc:mysql://localhost:3306/test"></property><property name="username" value="root"></property> <property name="password" value="123"></property> </bean> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:Configuration.xml"></property> <property name="dataSource" ref="dataSource"></property> </bean></beans> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:Configuration.xml"></property> <property name="dataSource" ref="DBPoolDataSource"></property> </bean></beans>
userMap.xml 示例:
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd"><mapper namespace="com.hoperun"> <select id="selectUser" parameterType="int" resultType="com.hoperun.bean.User"> select * from student where id = #{Id} </select></mapper>
- 整合Spring和Mybatis 中org.springframework.beans.factory.BeanCreationException错误
- SpringMVC+Mybatis+Spring整合中org.springframework.beans.factory.BeanCreationException错误分析
- org.springframework.beans.factory.BeanCreationException: 某个错误
- org.springframework.beans.factory.BeanCreationException错误解析
- org.springframework.beans.factory.BeanCreationException: 错误
- 错误:org.springframework.beans.factory.BeanCreationException
- org.springframework.beans.factory.BeanCreationException 错误
- spring org.springframework.beans.factory.BeanCreationException
- org.springframework.beans.factory.BeanCreationException
- org.springframework.beans.factory.BeanCreationException
- org.springframework.beans.factory.BeanCreationException
- org.springframework.beans.factory.BeanCreationException
- org.springframework.beans.factory.BeanCreationException
- org.springframework.beans.factory.BeanCreationException:
- org.springframework.beans.factory.BeanCreationException
- org.springframework.beans.factory.BeanCreationException
- org.springframework.beans.factory.BeanCreationException
- org.springframework.beans.factory.BeanCreationException
- 使用JMeter做性能测试的心得
- 让eclipse编辑器显示代码的行数
- 添加遮罩层
- ASCII Table
- 12.5 友元
- 整合Spring和Mybatis 中org.springframework.beans.factory.BeanCreationException错误
- 第14节 类和对象
- 用户方式中线程的同步
- 程序员到项目经理
- 使用PostThreadMessage在Win32线程间传递消息
- NEFU要崛起——第4场 A - Chat Server's Outgoing Traffic
- NO.84 ADF Mobile起步
- ios和安卓给后台上传图片代码
- Linux 关中断 与 开中断