Search code examples
javaspring-bootmaventomcatwar

How to give url path in spring boot refer to local file


I am trying to consume the WSDL file in the spring boot application, WSDL file is placed into the src/main/resource/wsdl/file.wsdl.

Project structure:

enter image description here

Code:

static {
   URL url = null;
   try {            
      url = new URL("file:///" + System.getProperty("user.dir") + "/src/main/resources/wsdl/outbound.wsdl");
   } catch(IOException e) { 
      java.util.logging.Logger
            .getLogger(OutboundService.class.getName())
            .log(java.util.logging.Level.INFO,
                 "Can not initialize the default wsdl from {0}", 
                 "file:/D:/ERPLOGIC/ERPProjects/JAVA/mavenproject/eclipse-workspace/topconpoc/src/main/resources/wsdl/outbound.wsdl");
   }
   WSDL_LOCATION = url;
}

It works fine in locally, but when deployed in the AWS server as a war file, it does not work.

What is the proper to refer to the path in the Spring Boot application?


Solution

  • Try this

    URL url = Thread.currentThread().getContextClassLoader().getResource("wsdl/outbound.wsdl");
    

    This should work