Spring boot 使用Spring boot读取内部和外部属性文件

Spring boot 使用Spring boot读取内部和外部属性文件,spring-boot,Spring Boot,1.properties位于src/main/resources中 2.属性位于服务器位置项目位置 I have a spring boot application jar @SpringBootApplication @EnableScheduling @PropertySource({"classpath:1.properties","classpath:2.properties"}) public class MyClass { //My class

1.properties位于src/main/resources中 2.属性位于服务器位置项目位置

I have a spring boot application jar

    @SpringBootApplication
    @EnableScheduling
    @PropertySource({"classpath:1.properties","classpath:2.properties"})
    public class MyClass {
//My class

    }

但我在启动应用程序时未找到2.properties的文件。请告诉我这里可能缺少什么

如评论中所述,您的
2.properties
文件不在
类路径下。如果文件确实存在于
jar
war
中,则只能使用
classpath

要获取
2.properties
属性,应该使用命令
file:
,而不是
classpath:

| MyClass.jar
| config
        | 2.properties

我不确定是否仍然需要OS环境变量或系统属性来设置属性文件的路径。在本例中,我将其命名为
application\u home

如果您的
2.properties
文件在jar之外,那么您将无法在类路径中找到它。我将它保存在与jar平行的配置文件夹中。所以配置文件夹也应该在类路径中可用,对吗?我把它保存在一个配置文件夹中,它与jar并行。所以配置文件夹也应该在类路径中可用,对吗?
@PropertySource("classpath:1.properties","file:${application_home}2.properties")