The content of element type "configuration" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,reflectorFactory?,plugins?,environments?,databaseIdProv

在mybatis配置文件config.xml中报错:

The content of element type "configuration" must match
"(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,reflectorFactory?,plugins?,environments?,databaseIdProvider?,mappers?)".

是因为配置信息的顺序放置错误,应遵循:

元素类型“配置”的内容必须匹配
“(属性?,设置?,typealiases?,typehandlers?、化?,objectwrapperfactory?,reflectorfactory?,插件吗?,环境?,databaseidprovider?,映射?)”。

示例代码

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://www.mybatis.org/dtd/mybatis-3-config.dtd">
<!--configuration根标签-->
<configuration>

    <!--    二、(1)    定义实体bean名和数据库列名相对应  type:实体的路径   alias:实体的别名 -->
    <typeAliases>
        <typeAlias type="com.ckx.entity.User" alias="User" />
    </typeAliases>
    
    <!--二、 (2)    引入关系映射文件!!!这里有严格顺序!不能放在数据源配置前-->
    <mappers>
        <mapper resource="com.ckx.entityMapper.UserMapper.xml" />
    </mappers>

    <!--一、    配置环境信息-->
    <environments default="admin">
        <environment id="admin">
            <!--            指定事务管理机制-->
            <transactionManager type="JDBC"></transactionManager>
            <!--            配置数据源   POOLED: 连接池-->
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost:3306/ceshi?useUnicode=true&amp;characterEncoding=utf8" />
                <property name="username" value="root" />
                <property name="password" value="123456" />
            </dataSource>
        </environment> 
    </environments>
    
    
    

</configuration>

改变顺序即可消除错误:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://www.mybatis.org/dtd/mybatis-3-config.dtd">
<!--configuration根标签-->
<configuration>

    <!--    二、(1)    定义实体bean名和数据库列名相对应  type:实体的路径   alias:实体的别名 -->
    <typeAliases>
        <typeAlias type="com.ckx.entity.User" alias="User" />
    </typeAliases>

    <!--一、    配置环境信息-->
    <environments default="admin">
        <environment id="admin">
            <!--            指定事务管理机制-->
            <transactionManager type="JDBC"></transactionManager>
            <!--            配置数据源   POOLED: 连接池-->
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost:3306/ceshi?useUnicode=true&amp;characterEncoding=utf8" />
                <property name="username" value="root" />
                <property name="password" value="123456" />
            </dataSource>
        </environment> 
    </environments>
    
    <!--二、 (2)    引入关系映射文件!!!这里有严格顺序!不能放在数据源配置前-->
    <mappers>
        <mapper resource="com.ckx.entityMapper.UserMapper.xml" />
    </mappers>
    

</configuration>

 

posted on 2016-11-13 21:33  ckx0709  阅读(3273)  评论(0编辑  收藏  举报

导航