Exception in integration with Hibernate when using my own classloader
.uclClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.uclClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 45 more The main method:
Code: public static void main(String[] args) throws Exception { CPClassLoader ccl = new CPClassLoader(TestLoader.class.getClassLoader(), quot;project1quot;); Thread.currentThread().setContextClassLoader(ccl); ccl.setDefintion(quot;d:/work/project1/libquot;, quot;d:/work/project1/classesquot;); Class clazz1 = ccl.loadClass (quot;com.abc.ObjectServicequot;); IService service = (IService)clazz1.newInstance(); IConfigMgr mgr = service.getConfigMgr(); mgr.setValue(quot;AAAAAquot;, quot;TestKeyquot;, quot;TestValuequot;); System.out.println(mgr.getValue(quot;AAAAAquot;, quot;TestKeyquot;)); Collectionlt;Configgt; configs = mgr.getConfigs(quot;AAAAAquot;); } 1) I have my own classloader named CPClassLoader which extends from uclClassLoader; and it's surely all of the necessary .jar files are put into the folder quot;d:/work/project1/libquot;. 2) The quot;ObjectServicequot; class is put into the quot;D:/work/project1/classesquot; and it will initializes the ApplicationContext when quot;service.getConfigMgr()quot;; the exception occurs when the applicationcontext initializing. 3) It will success when I do not put any DB beans (hibernate etc) in the spring applicationcontext.xml; 4) Please pay attention to the last lines of the Exception, it seems the application requests the class quot;org.hibernate.proxy.HibernateProxyquot; not using my own classloader. 5) I debug the code and found the exception thrown in cglib, after it tried to load the class quot;Configquot; with the AppClassLoader (not my own, I think it is right) , which is also the pojo class mapping to DB, because the main method may need the quot;Configquot; pojo class, so I do not put that class under the folder quot;d:/work/project1/classesquot;. I think it's maybe the the fault of cglib; the POJO class quot;Configquot; should be put under the folder quot;d:/work/project1/classesquot;? How can I do when I want the POJO class both in the main method and DB access?
Thanks
RedAvens
I am not familiar with the CGLIB, is there anyone could help me? |