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

标签 java spring spring-boot soap

我有一个 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")

Here一些解释。

关于java - 如何引用 src/main/resources 文件夹中的 .wsdl 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58545745/

相关文章:

java - Spring Cloud Config Server 环境变量的优先级

java - Spring Boot 无法从非字符串类型的字段的 POST 请求将 JSON 转换为 pojo

java - 如何在 Spring Data 中将 Java 实体映射到多个 MongoDB 集合?

java - Jackson FasterXML POJO 到 XML 列表

java - 以编程方式设置 Selenium 代理

java - map 与列表

java - 在jsp中转义<%%>

java - Spring Boot应用程序无法启动可能是由于依赖关系

java - 如何将 Spring Framework 源代码导入到 eclipse 项目中?

java - Spring 启动中使用的System.getenv()在sonarQube中显示为安全漏洞