简体   繁体   English

无法访问外部 xml 配置文件 spring 启动 jar

[英]unable to access outside xml config file in spring boot jar

am trying to use an xml file from outside jar.now its getting null pointer exception我正在尝试使用 jar 外部的 xml 文件。现在它得到 null 指针异常

 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;
    }

Configuration配置

public class ConfigurationFactory
{

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

how can i use external file in an executable jar如何在可执行 jar 中使用外部文件

error log错误日志

Caused by: java.lang.NullPointerException

You should use java.util.Properties to access external file, refer to this answer to load xml properties file您应该使用 java.util.Properties 访问外部文件,请参阅答案以加载 xml 属性文件

In your property file try:在您的属性文件中尝试:

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

Or annotate your configuration file with following或使用以下注释您的配置文件

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM