如何引用src/main/resources文件夹中的.wsdl文件



我有一个SOAP Web服务,我使用wsimport.wsdl中提取

现在,当打开生成的文件时,我有一个file://引用,我需要删除它。

我将WSDL移动到src/main/resources/Services/RecherchePoint-v2.0.wsdl

但现在,我有几个参考资料我不知道如何更新:

@WebServiceClient(name = "RecherchePointV2.0", targetNamespace = "http://www.enedis.fr/sge/b2b/services", wsdlLocation = "file:/home/ubuntu/wsdl/Services/RecherchePoint/RecherchePoint-v2.0.wsdl")
...
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("file:/home/ubuntu/wsdl/Services/RecherchePoint/RecherchePoint-v2.0.wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
RECHERCHEPOINTV20_WSDL_LOCATION = url;
RECHERCHEPOINTV20_EXCEPTION = e;
}

我尝试更改:

file:/home/ubuntu/wsdl/Services/RecherchePoint/RecherchePoint-v2.0.wsdl"

../../../resources/wsdl/Services/RecherchePoint/RecherchePoint-v2.0.wsdl"

但它不起作用。

知道怎么改变吗?

您可以使用org.springframework.core.io.ClassPathResource

/**
* {@link Resource} implementation for class path resources. Uses either a
* given {@link ClassLoader} or a given {@link Class} for loading resources.
*
* <p>Supports resolution as {@code java.io.File} if the class path
* resource resides in the file system, but not for resources in a JAR.
* Always supports resolution as URL.
*
*/
new ClassPathResource("Services/RecherchePoint-v2.0.wsdl")

这里有一些解释。

您可以将文件放在参考资料中,并可以使用类加载器来获取文件

ClassLoader classLoader = getClass().getClassLoader();  
File file = new File(classLoader.getResource("RecherchePoint-v2.0.wsdl").getFile());