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

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

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

PHP
四季花海 2019-12-11 14:09:39
java :load(Thread.currentThread().getContextClassLoader().getResourceAsStream("db.properties"))
查看完整描述

4 回答

?
狐的传说

TA贡献1804条经验 获得超3个赞

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

查看完整回答
反对 回复 2019-12-12
?
九州编程

TA贡献1785条经验 获得超4个赞

你可以尝试下面这种方式:  不知道是不是你想要的. 全部放入系统加载器里面.
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-12-12
  • 4 回答
  • 0 关注
  • 456 浏览

添加回答

举报

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