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

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


DIEA
浏览 790回答 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