我是一个Web服务,我将我的WSDL放在WEB-INF/classes
目录中的类路径中。我在tomcat服务器上运行以下代码。
第一种方法
static {
URL WSDL_LOC=WSClient.class.getClass().getClassLoader().getResource("Data.wsdl");
System.out.println("Location here is : " + WSDL_LOC);
}
第二种方法
static {
URL WSDL_LOC = Thread.currentThread().getContextClassLoader().getResource("Data.wsdl");
System.out.println("Location here is : " + WSDL_LOC);
}
当我在tomcat tyhe中运行我的战争时,第一种方法在控制台上打印null
,而第二个控制台实际上正确打印它。我只是想知道为什么会这样,以及这样做的正确方法是什么。
我的期望是使用静态引用WSClient的第一个引用使用系统类加载器,而使用当前线程的第二个引用使用tomcat的Web应用程序类加载器。
阅读此链接Difference between thread's context class loader and normal classloader