【问题标题】:unable to access outside xml config file in spring boot jar无法访问spring boot jar中的外部xml配置文件
【发布时间】:2019-10-24 07:27:29
【问题描述】:

我正在尝试使用外部 jar 中的 xml 文件。现在它得到空指针异常

 private static String getRequestConfigurationLocation() throws UnsupportedEncodingException
    {
        URL resourceURL = ConfigurationFactory.class.getResource(Configuration.XML_CONF);
        //Assert.notNull(resourceURL, "Resource url is null : ");
        String urlFilePath = resourceURL.getFile();
        String actualFilePath = java.net.URLDecoder.decode(urlFilePath, StandardCharsets.UTF_8.name());
        return actualFilePath;
    }

配置

public class ConfigurationFactory
{

    public static final String XML_CONF = "D:/DEV//X/X1/Service/target/conf/rConfiguration.xml";
}

如何在可执行 jar 中使用外部文件

错误日志

Caused by: java.lang.NullPointerException

【问题讨论】:

    标签: java spring-boot


    【解决方案1】:

    你应该使用 java.util.Properties 来访问外部文件, 参考this回答加载xml属性文件

    【讨论】:

      【解决方案2】:

      在你的属性文件中尝试:

      external.config=D:/DEV//X/X1/Service/target/conf/rConfiguration.xml

      或者 使用以下注释您的配置文件

      @配置 @ImportResource("D:/DEV//X/X1/Service/target/conf/rConfiguration.xml")

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-15
      • 2014-07-25
      • 1970-01-01
      • 2016-04-03
      • 2018-04-24
      • 2014-12-25
      • 2017-06-21
      • 2015-11-28
      相关资源
      最近更新 更多