Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 有没有办法让spring boot应用程序能够在参考资料中查看配置文件夹,并在需要时获取其配置?_Java_Spring_Spring Boot_Configuration_Resources - Fatal编程技术网

Java 有没有办法让spring boot应用程序能够在参考资料中查看配置文件夹,并在需要时获取其配置?

Java 有没有办法让spring boot应用程序能够在参考资料中查看配置文件夹,并在需要时获取其配置?,java,spring,spring-boot,configuration,resources,Java,Spring,Spring Boot,Configuration,Resources,我有一个config文件夹,其中包含我的spring boot应用程序所需的xml文件,它位于src文件夹的同一级别上。。。现在,我想在应用程序.properties的同一级别的资源文件夹中找到它。。有什么方法可以做到这一点?有很多方法可以读取您的文件。属性: 您可以使用普通java阅读以下内容: Properties properties = new Properties(); properties.load(Thread.currentThread().getContextClassLoad

我有一个config文件夹,其中包含我的spring boot应用程序所需的xml文件,它位于src文件夹的同一级别上。。。现在,我想在应用程序.properties的同一级别的资源文件夹中找到它。。有什么方法可以做到这一点?

有很多方法可以读取您的文件。属性:

您可以使用普通java阅读以下内容:

Properties properties = new Properties();
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName));
您可以在Spring
@Configuration
类中使用
@PropertySource
注释:

@Configuration
@PropertySource("db.properties")
public class ApplicationConfig {

    // more config ...
}
//Or if you your config outside of your classpath, you can use the file: prefix:
@PropertySource("file:/path/to/application.properties")
使用多个文件:

@PropertySources({
    @PropertySource("classpath:foo.properties"),
    @PropertySource("classpath:bar.properties")
})
public class PropertiesWithJavaConfig {
    //...
}

等等…

有很多方法可以读取文件。属性:

您可以使用普通java阅读以下内容:

Properties properties = new Properties();
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName));
您可以在Spring
@Configuration
类中使用
@PropertySource
注释:

@Configuration
@PropertySource("db.properties")
public class ApplicationConfig {

    // more config ...
}
//Or if you your config outside of your classpath, you can use the file: prefix:
@PropertySource("file:/path/to/application.properties")
使用多个文件:

@PropertySources({
    @PropertySource("classpath:foo.properties"),
    @PropertySource("classpath:bar.properties")
})
public class PropertiesWithJavaConfig {
    //...
}

等等…

Web搜索:。问题被否决了,因为它“没有显示任何研究成果”(引用了否决按钮的工具提示)我做了很多研究。。但我需要的是不同。。我有一个与jpos框架相关的xml文件配置文件夹,用于处理金融交易。。它不像jpos.isoChannel.port=5000然后从配置类中提取它。。不,它是一个需要启动的与JPO相关的xml配置文件。。现在它与src文件夹级别处于同一级别,现在我想将它放在resources文件夹中,并且仍然能够以与以前相同的方式查看它。
src/resources
文件夹中的任何文件在运行时都将位于类路径上,与
application.properties
文件相同。这是标准的Maven项目设置,与Spring Boot无关。如果您正在使用Spring阅读资源,请使用类。兄弟,我如何与您联系,因为我的问题比这复杂得多,那么您如何编辑问题并澄清您试图解决的问题。Web搜索:。问题被否决了,因为它“没有显示任何研究成果”(引用了否决按钮的工具提示)我做了很多研究。。但我需要的是不同。。我有一个与jpos框架相关的xml文件配置文件夹,用于处理金融交易。。它不像jpos.isoChannel.port=5000然后从配置类中提取它。。不,它是一个需要启动的与JPO相关的xml配置文件。。现在它与src文件夹级别处于同一级别,现在我想将它放在resources文件夹中,并且仍然能够以与以前相同的方式查看它。
src/resources
文件夹中的任何文件在运行时都将位于类路径上,与
application.properties
文件相同。这是标准的Maven项目设置,与Spring Boot无关。如果你正在阅读Spring的参考资料,请使用该课程。兄弟,我如何与你联系,因为我的问题比这复杂得多,那么你如何编辑问题并澄清你试图解决的问题。