本文主要是介绍The content of element type configuration must match (properties?,setting,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在运行mybatis配置文件的时候,出现错误:
- Caused by: org.xml.sax.SAXParseException: The content of element type "configuration" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,plugins?,environments?,databaseIdProvider?,mappers?)".
- at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
- at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
- at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
- at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
- at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.java:2017)
- at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:901)
- at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1774)
- at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2930)
- at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
- at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
- at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
- at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
- at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
- at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
- at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
- at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:254)
- ... 21 more
配置文件如下:
- <?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">
- <configuration>
- <properties resource="dbConfig.properties"></properties>
- <environments default="development">
- <environment id="development">
- <transactionManager type="JDBC" />
- <dataSource type="POOLED">
- <property name="driver" value="${driver}" />
- <property name="url" value="${url}" />
- <property name="username" value="${dbuser}" />
- <property name="password" value="${dbpassword}" />
- </dataSource>
- </environment>
- </environments>
- <mappers>
- <mapper resource="com/apps/dao/RemainDao.xml"/>
- <mapper resource="com/apps/dao/WorkSpaceDao.xml"/>
- </mappers>
- <typeAliases>
- <typeAlias type="com.apps.domain.Remian" alias="Remian"/>
- <typeAlias type="com.apps.domain.WorkSpace" alias="WorkSpace"/>
- </typeAliases>
- </configuration>
找了老半天,才发现配置文件 configuration 中的元素,不但有类型限制,也有顺序限制。必须按照(
- match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,plugins?,environments?,databaseIdProvider?,mappers?)".
)进行配置。修改配置文件
- <?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">
- <configuration>
- <properties resource="dbConfig.properties"></properties>
- <typeAliases>
- <typeAlias type="com.apps.domain.Remian" alias="Remian"/>
- <typeAlias type="com.apps.domain.WorkSpace" alias="WorkSpace"/>
- </typeAliases>
- <environments default="development">
- <environment id="development">
- <transactionManager type="JDBC" />
- <dataSource type="POOLED">
- <property name="driver" value="${driver}" />
- <property name="url" value="${url}" />
- <property name="username" value="${dbuser}" />
- <property name="password" value="${dbpassword}" />
- </dataSource>
- </environment>
- </environments>
- <mappers>
- <mapper resource="com/apps/dao/RemainDao.xml"/>
- <mapper resource="com/apps/dao/WorkSpaceDao.xml"/>
- </mappers>
- </configuration>
之后可以通过.........
这篇关于The content of element type configuration must match (properties?,setting的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!