问题:今天在写mybatis plugin插件的时候碰到如下错误:
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)
分析:解析xml的plugins出现问题。
原因:Mybatis3.X 的版本使用的 dtd 作为 XML 的格式校验文档。 而在 XML 规范中,dtd 是有严格的顺序的,在报错的异常中已经列出了对应的顺序,所以必须进行严格匹配:plugins必须写在mappers之前。
<plugins>
<plugin interceptor="com.steven.interceptor.PageInterceptor">
<property name="databaseType" value="mysql"/>
</plugin>
</plugins>
<mappers>
<mapper resource="mapper/Order.xml"/>
<mapper resource="mapper/Workflow.xml"/>
<mapper resource="mapper/PacificLog.xml"/>
<mapper resource="mapper/OrderMapping.xml"/>
<mapper resource="mapper/PacificAgreementInstance.xml"/>
<mapper resource="mapper/PlatformRelation.xml"/>
<mapper resource="mapper/PlatformRelationAttributes.xml"/>
</mappers>
参考:http://www.cnblogs.com/myssh/p/5404936.html