java.lang.ClassNotFoundException: Cannot find class: DB_VENDOR

原创 2014年09月15日 23:28:32

在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: Cannot find class: BaseResultMap

出现这种状况,别捉急,直接去相应的model对应的mapping中将resultType改成resultMap即可...
  • ljj821061514
  • ljj821061514
  • 2016年07月15日 11:06
  • 5136

Caused by: java.lang.ClassNotFoundException: Cannot find class:

Caused by: java.lang.ClassNotFoundException: Cannot find class:严重: Exception sending context initial...
  • testcs_dn
  • testcs_dn
  • 2017年09月04日 19:01
  • 2281

java.lang.ClassNotFoundException:

我遇到的这个问题是在使用天工的sdk与web 框架整合的时候,我web框架使用的是ssm框架,用maven来管理jar包,使用天工的包的时候,直接作为jar包添加到building path中,然后启...
  • liliang950210
  • liliang950210
  • 2017年04月09日 11:09
  • 217

java.lang.ClassNotFoundException

我们经常在使用eclipse中启动tomcat服务,然后经常在启动的时候抛出  java.lang.ClassNotFoundException 这个异常,一般出现这种情况的时候,是因为我们并没有引入...
  • lovin_fang
  • lovin_fang
  • 2017年08月12日 14:43
  • 80

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.***.client.v1.Mai

Caused by: java.lang.ClassNotFoundException[android的终极解决错误] 08-13 18:29:22.924: E/AndroidRuntim...
  • berry666
  • berry666
  • 2014年08月18日 10:43
  • 15906

Caused by: java.lang.ClassNotFoundException: Cannot find class: com.github.pagehelper.PageIntercepto

今天使用pageHelper一直报这个错误 可能原因1:jar包和参数配置不匹配的问题 参考这个博客 http://blog.csdn.net/zheng0518/article/details/...
  • qq_31204567
  • qq_31204567
  • 2017年10月07日 22:22
  • 602

由代码混淆引发的java.lang.ClassNotFoundException

完整错误日志如下: I/Chiron ( 57): java.lang.ClassNotFoundException: Didn't find class "com.alta.audiopoli...
  • harry_helei
  • harry_helei
  • 2017年03月31日 10:35
  • 838

java常见的ClassNotFoundException

1 - java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory    添加包common-logging.ja...
  • niqinwen
  • niqinwen
  • 2012年05月23日 15:24
  • 3252

java.lang.ClassNotFoundException web项目加载时找不到类

程序出现ClassNotFoundException 的时候,别着急,俺陪你一起找。这个错误可能是这样的,也可能是这样的,最后是这样的!...
  • chenqk_123
  • chenqk_123
  • 2015年04月09日 16:39
  • 26580

java.lang.ClassNotFoundException: Didn't find class "*****Activity" on path: /data/app/*******.apk

很多人出现了java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{*****Activity}: java....
  • lovexieyuan520
  • lovexieyuan520
  • 2013年06月05日 17:53
  • 70718
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:java.lang.ClassNotFoundException: Cannot find class: DB_VENDOR
举报原因:
原因补充:

(最多只允许输入30个字)