簡體   English   中英

Spring無法使用@PropertySource查找類路徑資源

[英]Spring not able to find classpath resource with @PropertySource

我在數據源配置文件中使用@PropertySource來獲取位於類路徑上的屬性文件。 下面是我的項目結構。

在此處輸入圖片說明

我相信我可以通過兩種方式做到這一點:

  1. 通過在src文件夾中創建一個軟件包並將其添加到那里。 由於src文件夾已經包含在eclipse中的類路徑中,因此應該可以進行以下操作。

@PropertySources({@PropertySource(“ classpath:com / spring / property / general.properties”),@PropertySource(“ classpath:com / spring / property / hibernate.properties”)})

  1. 第二種方法是創建一個resources文件夾並將其添加到類路徑中,以下應該可以工作

@PropertySources({@ PropertySource(“ classpath:general.properties”),@PropertySource(“ classpath:hibernate.properties”)})

就我而言,兩者都不起作用。 作為中級Java開發人員,這仍然讓我感到困惑。 誰能指導我正確的方向。 以及我們如何在生產環境中為Spring配置類路徑資源。

編輯 :我已經更改了項目結構,以在src/java/resources包含屬性文件,並且可以在構建路徑中看到resources文件夾。 春季仍然找不到.properties

在此處輸入圖片說明

對於任何在Spring 4+中遇到usign .properties文件問題的人,請查看下面的線程以將您的設置與OP匹配。 除配置中有空格外,安裝程序都很好。

無法使用@PropertySource將.properties文件注入Spring MVC 4.3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM