请教一下关于java :load(Thread.currentThread())?

java :load(Thread.currentThread().getContextClassLoader().getResourceAsStream("db.properties"))


四季花海
浏览 466回答 4
4回答

狐的传说

getResource("") 返回的当然是null了获取classpath的值使用System.getProperty(“java.class.path”);

九州编程

你可以尝试下面这种方式:  不知道是不是你想要的. 全部放入系统加载器里面.ClassLoader classLoader=ClassLoader.getSystemClassLoader();Thread thread0=new Thread();thread0.currentThread().setContextClassLoader(classLoader);Thread thread1=new Thread();thread1.currentThread().setContextClassLoader(classLoader);Thread thread2=new Thread();thread2.currentThread().setContextClassLoader(classLoader);System.out.println(thread0.getContextClassLoader());System.out.println(thread1.getContextClassLoader());System.out.println(thread2.getContextClassLoader());
打开App,查看更多内容
随时随地看视频慕课网APP