为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

DIEA 2019-10-21 17:13:56
java :load(Thread.currentThread().getContextClassLoader().getResourceAsStream("db.properties"))
查看完整描述

4 回答

?
富国沪深

TA贡献1790条经验 获得超9个赞

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

查看完整回答
反对 回复 2019-10-26
?
吃鸡游戏

TA贡献1829条经验 获得超7个赞

你可以尝试下面这种方式:  不知道是不是你想要的. 全部放入系统加载器里面.
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());

查看完整回答
反对 回复 2019-10-26
  • 4 回答
  • 0 关注
  • 771 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信