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