Java.lang.ClassNotFoundException:Cannot Find Class:db_vendor

Source: Internet
Author: User
Tags log4j

When using the Databaseidprovider node configuration item (<databaseidprovider type= "Db_vendor" >) in MyBatis, the following error message appears:

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: # # # Error Building sqlsession.### the  Error 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_vendorat 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_vendorat 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 morecaused 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_vendorat 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 morecaused by:org.apache.ibatis.type.TypeException:Could not resolve type alias ' DB_vendor '. Cause:java.lang.ClassNotFoundException:Cannot Find Class:db_vendorat 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 morecaused By:java.lang.ClassNotFoundException:Cannot Find Class:db_vendorat 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

The reason is that Db_vendor is the alias that was used since the 3.2.3 version, 3.2.3 (not included) the previous board does not support this name and requires the use of vendor.

From the MyBatis source code, you can see:

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); }}

While the 3.2.3 XML file was initialized, the vendor conversion was used to support the owner's 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 = Co Ntext.getchildrenasproperties ();      Databaseidprovider = (databaseidprovider) resolveclass (type). newinstance ();      Databaseidprovider.setproperties (properties);}}}  


In the previous code, Db_vendor is not supported: 3.2.3

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 databaseId Providerelement (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) {& nbsp;     String databaseId = Databaseidprovider.getdatabaseid (Environment.getdatasource ());       Configuration.setdatabaseid (databaseId);    } }} 

Therefore, this issue is likely to be raised if you are using the old package and you are using a new document development.

Java.lang.ClassNotFoundException:Cannot Find Class:db_vendor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.