在mybatis 中使用databaseIdProvider节点配置项(<databaseIdProvider type="DB_VENDOR">)时, 出现如下错误提示:
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The error may exist in SQL Mapper Configuration ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'DB_VENDOR'. Cause: java.lang.ClassNotFoundException: Cannot find class: DB_VENDOR at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:79) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:63) at testMybatis.Test.main(Test.java:20) Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'DB_VENDOR'. Cause: java.lang.ClassNotFoundException: Cannot find class: DB_VENDOR at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:106) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:89) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:77) ... 2 more Caused by: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'DB_VENDOR'. Cause: java.lang.ClassNotFoundException: Cannot find class: DB_VENDOR at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:100) at org.apache.ibatis.builder.xml.XMLConfigBuilder.databaseIdProviderElement(XMLConfigBuilder.java:244) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:102) ... 4 more Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias 'DB_VENDOR'. Cause: java.lang.ClassNotFoundException: Cannot find class: DB_VENDOR at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:114) at org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:127) at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:98) ... 6 more Caused by: java.lang.ClassNotFoundException: Cannot find class: DB_VENDOR at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:188) at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:87) at org.apache.ibatis.io.Resources.classForName(Resources.java:254) at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:110) ... 8 more
原因是DB_VENDOR是从3.2.3版本开始使用的别名,3.2.3(不含)以前的板本不支持此名称,需要使用VENDOR。
从mybatis源代码中可以看出:
V3.2.3
package org.apache.ibatis.session; public class Configuration { public Configuration() { typeAliasRegistry.registerAlias("JDBC", JdbcTransactionFactory.class); typeAliasRegistry.registerAlias("MANAGED", ManagedTransactionFactory.class); typeAliasRegistry.registerAlias("JNDI", JndiDataSourceFactory.class); typeAliasRegistry.registerAlias("POOLED", PooledDataSourceFactory.class); typeAliasRegistry.registerAlias("UNPOOLED", UnpooledDataSourceFactory.class); typeAliasRegistry.registerAlias("PERPETUAL", PerpetualCache.class); typeAliasRegistry.registerAlias("FIFO", FifoCache.class); typeAliasRegistry.registerAlias("LRU", LruCache.class); typeAliasRegistry.registerAlias("SOFT", SoftCache.class); typeAliasRegistry.registerAlias("WEAK", WeakCache.class); typeAliasRegistry.registerAlias("DB_VENDOR", VendorDatabaseIdProvider.class); typeAliasRegistry.registerAlias("XML", XMLLanguageDriver.class); typeAliasRegistry.registerAlias("RAW", RawLanguageDriver.class); typeAliasRegistry.registerAlias("SLF4J", Slf4jImpl.class); typeAliasRegistry.registerAlias("COMMONS_LOGGING", JakartaCommonsLoggingImpl.class); typeAliasRegistry.registerAlias("LOG4J", Log4jImpl.class); typeAliasRegistry.registerAlias("LOG4J2", Log4j2Impl.class); typeAliasRegistry.registerAlias("JDK_LOGGING", Jdk14LoggingImpl.class); typeAliasRegistry.registerAlias("STDOUT_LOGGING", StdOutImpl.class); typeAliasRegistry.registerAlias("NO_LOGGING", NoLoggingImpl.class); typeAliasRegistry.registerAlias("CGLIB", CglibProxyFactory.class); typeAliasRegistry.registerAlias("JAVASSIST", JavassistProxyFactory.class); languageRegistry.setDefaultDriverClass(XMLLanguageDriver.class); languageRegistry.register(RawLanguageDriver.class); } }
而在3.2.3的xml文件初始化时,使用了VENDOR转换,可以同时支持老板本的VENDOR:
package org.apache.ibatis.builder.xml; public class XMLConfigBuilder extends BaseBuilder { private void databaseIdProviderElement(XNode context) throws Exception { DatabaseIdProvider databaseIdProvider = null; if (context != null) { String type = context.getStringAttribute("type"); if ("VENDOR".equals(type)) type = "DB_VENDOR";// awful patch to keep backward compatibility Properties properties = context.getChildrenAsProperties(); databaseIdProvider = (DatabaseIdProvider) resolveClass(type).newInstance(); databaseIdProvider.setProperties(properties); } } }
而在3.2.3以前的代码中,则不支持DB_VENDOR:
V3.2.2
package org.apache.ibatis.session; public class Configuration { public Configuration() { typeAliasRegistry.registerAlias("JDBC", JdbcTransactionFactory.class); typeAliasRegistry.registerAlias("MANAGED", ManagedTransactionFactory.class); typeAliasRegistry.registerAlias("JNDI", JndiDataSourceFactory.class); typeAliasRegistry.registerAlias("POOLED", PooledDataSourceFactory.class); typeAliasRegistry.registerAlias("UNPOOLED", UnpooledDataSourceFactory.class); typeAliasRegistry.registerAlias("PERPETUAL", PerpetualCache.class); typeAliasRegistry.registerAlias("FIFO", FifoCache.class); typeAliasRegistry.registerAlias("LRU", LruCache.class); typeAliasRegistry.registerAlias("SOFT", SoftCache.class); typeAliasRegistry.registerAlias("WEAK", WeakCache.class typeAliasRegistry.registerAlias("VENDOR", VendorDatabaseIdProvider.class); typeAliasRegistry.registerAlias("XML", XMLLanguageDriver.class); typeAliasRegistry.registerAlias("RAW", RawLanguageDriver.class); typeAliasRegistry.registerAlias("SLF4J", Slf4jImpl.class); typeAliasRegistry.registerAlias("COMMONS_LOGGING", JakartaCommonsLoggingImpl.class); typeAliasRegistry.registerAlias("LOG4J", Log4jImpl.class); typeAliasRegistry.registerAlias("JDK_LOGGING", Jdk14LoggingImpl.class); typeAliasRegistry.registerAlias("STDOUT_LOGGING", StdOutImpl.class); typeAliasRegistry.registerAlias("NO_LOGGING", NoLoggingImpl.class); typeAliasRegistry.registerAlias("CGLIB", CglibProxyFactory.class); typeAliasRegistry.registerAlias("JAVASSIST", JavassistProxyFactory.class); languageRegistry.setDefaultDriverClass(XMLLanguageDriver.class); languageRegistry.register(RawLanguageDriver.class); } }
package org.apache.ibatis.builder.xml; public class XMLConfigBuilder extends BaseBuilder { private void databaseIdProviderElement(XNode context) throws Exception { DatabaseIdProvider databaseIdProvider = null; if (context != null) { String type = context.getStringAttribute("type"); Properties properties = context.getChildrenAsProperties(); databaseIdProvider = (DatabaseIdProvider) resolveClass(type).newInstance(); databaseIdProvider.setProperties(properties); } Environment environment = configuration.getEnvironment(); if (environment != null && databaseIdProvider != null) { String databaseId = databaseIdProvider.getDatabaseId(environment.getDataSource()); configuration.setDatabaseId(databaseId); } } }
因此如果在使用旧的包,而又对应使用新的文档开发时,很可能引发此问题
相关推荐
"java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver" 解决方案 [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket. 解决了jsp连接 sql server 2000的问题
在Java编程中,`java.lang.ClassNotFoundException`是一个常见的运行时异常,它表示JVM尝试加载一个类时,找不到对应的.class文件。在这个特定的错误中,我们看到的是`org.apache.commons.dbcp.BasicDataSource`,这...
在Java编程中,`java.lang.ClassNotFoundException` 是一个常见的运行时异常,通常发生在尝试通过类加载器加载指定类时,但找不到对应的字节码文件。在这个特定的问题中,`ClassNotFoundException` 引发的原因是缺少...
然而,对于初学者来说,遇到错误是常有的事,比如“java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource”。这个异常表明在运行时,系统无法找到指定的类,即Apache Commons DBCP的...
在Java编程中,`ClassNotFoundException` 是一个常见的运行时异常,通常发生在尝试加载特定类时,JVM无法找到对应类的定义。在这个特定的情景中,错误提示 "java.lang.ClassNotFoundException: ...
Java中的`ClassNotFoundException`异常通常表示在尝试加载特定类时,JVM无法找到对应的字节码文件。这个异常可能由多种原因引起,但在本场景中,它与Java 9引入的模块系统及其对Java EE API的影响密切相关。 在Java...
at java.net.URLClassLoader.findClass(URLClassLoader.java:434) at com.ibm.ws.bootstrap.ExtClassLoader.findClass(ExtClassLoader.java:204) at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:688...
总之,解决“java.lang.ClassNotFoundException: org.jdom.input.SAXBuilder”问题的关键在于确保JDOM库被正确地包含在类路径中,同时检查代码中涉及的类名拼写是否准确。了解并熟练使用SAXBuilder可以帮助开发者...
java.lang.NoClassDefFoundError: com/sun/activation/registries/LogSupport异常处理
接口调用报错:java.net.SocketException: java.lang.ClassNotFoundException: Cannot find the specified class com.ibm.websphere.ssl.protocol.SSLSocketFactory
Caused by: java.sql.SQLException: java.lang.ClassNotFoundException: org.apache.hive.jdbc.HiveDriver at com.trs.gateway.commons.hive.HiveFeature.getConnection(HiveFeature.java:57) at ...
在Java编程中,`ClassNotFoundException` 是一个常见的运行时异常,表示尝试加载某个类时,在类路径中找不到对应的`.class`文件。在这个特定的场景中,异常堆栈跟踪显示 `Caused by: java.lang....
在这个特定的场景中,异常堆栈跟踪显示了 `Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.Transformer`,这表明系统无法找到 `org.apache.commons.collections.Transformer` 类。...
Android Caused by: java.lang.ClassNotFoundException解决办法 出现问题: 08-13 18:29:22.924: E/AndroidRuntime(1875): Caused by: Java.lang.ClassNotFoundException:XXXXX in loader dalvik.system....
【SpringBoot】Error: java.lang.ClassNotFoundException: org.wltea.analyzer.core.IKSegmenter报错明细问题分析后记 报错明细 IDEA SpringBoot集成hadoop运行... at java.net.URLClassLoader.findClass(URLClassLoade
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory 需要jar log4j-1.2.16.jar slf4j-api-1.6.1.jar slf4j-log4j12-1.6.1.jar
一:查看你下载的MySQL和mysql-connector-java,如果不对应的话肯定会报错。 对应规则: mysql-connector-java-5 Connector/J version Driver Type JDBC version MySQL Server version Status 5.1 4 3.0, 4.0...
深入浅出Java_Swing程序设计(高清),第二部分,分卷压缩 Swing开发入门经典教材