The pits of Appclassloader and Webappclasssloader

Source: Internet
Author: User

Recently, I'm going to learn spring MVC and do some accumulating for follow-up.

Build Spring+mybatis, dynamically create Mapper,mapper file names and classes in a directory, but before I make a

Error, case is wrong, the result I run with ordinary Java program, no problem, the result is deployed under Tomcat, always

Newspaper statement can't find, strange, Java program can find AH.

To be sure two programs classloader different, one is system, one is tomcat.

Go deep and find the MyBatis code, as follows:

Private voidLoadxmlresource () {//Spring may isn't know the real resource name so we check a flag//To prevent loading again a resource twice//This flag was set at Xmlmapperbuilder#bindmapperfornamespace        if(!configuration.isresourceloaded ("namespace:" +type.getname ())) {String Xmlresource= Type.getname (). replace ('. ', '/') + '. Xml '; InputStream InputStream=NULL; Try{System.out.println ("ClassLoader:" +Type.getclassloader ()); InputStream=Resources.getresourceasstream (Type.getclassloader (), Xmlresource); } Catch(IOException e) {//Ignore, resource is not required            }            if(InputStream! =NULL) {Xmlmapperbuilder Xmlparser=NewXmlmapperbuilder (InputStream, Assistant.getconfiguration (), Xmlresource, config                Uration.getsqlfragments (), Type.getname ());            Xmlparser.parse (); }        }    }

Strange, is to use the ClassLoader load, supposedly no problem, are the classpath below.

Look for the class name corresponding to the XML, supposedly said two behavior should be the same ah, are not found, can not find one, one did not find.

Later thought, in the Windows platform file case does not distinguish it, the result is decisive to change the name, the result is normal.

I went, it may be I understand less knowledge, it is too pit. Although the configuration is wrong is my problem .....

The pits of Appclassloader and Webappclasssloader

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.