MyBatis 元素类型为 "configuration" 的内容必须匹配 ".....
修改MyBatis配置文件时,添加typeAliases节点,报了一个BuilderException:
org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 35; columnNumber: 17; 元素类型为 "configuration" 的内容必须匹配 "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,plugins?,environments?,databaseIdProvider?,mappers?)"。 at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:82) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:66)
原因是Mybatis3.X 的版本使用的 dtd 作为 XML 的格式校验文档。 而在 XML 规范中,dtd 是有严格的顺序的,在报错的异常中已经列出了对应的顺序,应该为:
properties>settings>typeAliases>typeHandlers>objectFactory>objectWrapperFactory>plugins>environments>databaseIdProvider>mappers