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

时间:2019-10-24 16:43:12

标签: java spring spring-boot soap

我有一个使用.wsdlwsimport提取的SOAP Web服务

现在,在打开生成的文件时,我需要删除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"

但它不起作用。

任何想法如何更改它?

2 个答案:

答案 0 :(得分:0)

您可以将文件放置在Resources中,并且可以使用类加载器来获取文件

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

答案 1 :(得分:0)

您可以使用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")

Here一些解释。