Mybatis如何使用databaseIdProvider

chengdudashu chengdudashu 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

<!-- 配置环境变量 -->
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@10.9.220.131:1521:test"/>
<property name="username" value="123" />
<property name="password" value="123" />
</dataSource>
</environment>
</environments>

[color=#800000]<!-- 数据库配置 -->
<databaseIdProvider type="DB_VENDOR">
<property name="DB2" value="db2"/>
<property name="Oracle" value="oracle" />
<property name="Adaptive Server Enterprise" value="sybase"/>
<property name="MySQL" value="mysql" />
</databaseIdProvider>
[/color]

在mybatis的配置文件中,只要加入红色的部分,就会报错。
请问:
1. databaseIdProvider 应该怎么使用呢?
2. 使用databaseIdProvider可以实现在不同类型的数据库切换,但是如果在同一类型的不同数据库查询(比如有两个oracle的数据库),应该怎么查询呢?mybatis支持吗?
谢谢。

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException: Element type "databaseIdProvider" must be declared.
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:60)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:44)
at com.zxc.mybatis.App.main(App.java:25)
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException: Element type "databaseIdProvider" must be declared.
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:238)
at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:107)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.<init>(XMLConfigBuilder.java:52)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:57)
... 2 more
Caused by: org.xml.sax.SAXParseException: Element type "databaseIdProvider" must be declared.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:236)
... 5 more

...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
chengdudashu
Web 开发 81,108 成员 341,721 内容