2017-10-17 47 views
1
I have a spring boot application jar 

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

    } 

1.properties閱讀內部和外部的屬性文件在src /主/資源 2.properties是服務器位置項目位置使用Spring啓動

| MyClass.jar 
| config 
     | 2.properties 

但我越來越找不到文件爲2.properties啓動應用程序。請讓我知道我可能會錯過這裏。

+1

如果你的'2.properties'文件在jar之外,那麼你不會在類路徑上找到它 – Catchwa

+0

我已經將它保存在與jar平行的配置文件夾中。所以這個config文件夾也應該在類路徑中可用? – TomJava

回答

1

像在評論中提到的,您的2.properties文件不在您的classpath下。如果您的文件確實存在於您的jarwar中,則只能使用classpath

要得到2.properties您應該使用命令file:而不是classpath:

@PropertySource("classpath:1.properties","file:${application_home}2.properties") 

我不太確定它是否仍然需要OS環境變量或系統屬性來設置屬性文件的路徑。在這種情況下,我將其命名爲application_home

+0

我把它保存在一個平行於jar的配置文件夾中。所以這個config文件夾也應該在類路徑中可用? – TomJava