整合Spring和Mybatis 中org.springframework.beans.factory.BeanCreationException错误

这两天学习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.xsd
http://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 configuration
PUBLIC "-//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>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值