版权声明:最终解释权归属Hern、HernSong(hernsong)、苍鹭、www.hernsong.com所有! https://blog.csdn.net/qq_36761831/article/details/88375153
错误
在配置Mybatis的时候明明配置项没有错,就会莫名其妙的报错:元素类型为 "configuration" 的内容必须匹配 "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,reflectorFactory?,plugins?,environments?,databaseIdProvider?,mappers?)
原因
配置节点必须按官方指定的顺序,顺序错了就会报以上的错误。
例如:
以下配置就会报错(因为typeAliases标签在properties标签前面):
<typeAliases>
<typeAlias type="com.mybatis.employee.Employee" alias="emp"></typeAlias>
</typeAliases>
<!--引入外部属性文件-->
<properties resource="db.properties"></properties>
以下配置就不会报错:
<!--引入外部属性文件-->
<properties resource="db.properties"></properties>
<!--
typeAliases别名处理器,可以为java类型(resultType)起别名
type指定要起别名的类型全类名;默认别名就是类名小写
-->
<typeAliases>
<typeAlias type="com.mybatis.employee.Employee" alias="emp"></typeAlias>
</typeAliases>