spring讀取配置檔案的幾種方式

2022-03-23 06:17:28 字數 533 閱讀 8633

場景

假如有以下屬性檔案dev.properties, 需要注入下面的tag

tag=123

通過propertyplaceholderconfigurer

**@value("$")

private string tag;

通過preferencesplaceholderconfigurer

**:@value("$")

private string tag;

通過propertiesfactorybean12

3123

**:@value("#")

private string tag;

通過util:properties

效果同propertiesfactorybean一樣

**:@value("#")

private string tag;

其他方式

有時也可以不通過檔案,直接寫字麵量

**:@value("$")

private string tag;

spring讀取配置檔案

一般來說。我們會將一些配置的資訊放在。properties檔案中。然後使用 將配置檔案中的資訊讀取至spring的配置檔案。那麼我們如何在spring讀取properties檔案呢。1.首先。我們要先在spring配置檔案中。定義乙個專門讀取properties檔案的類.例 classpath jd...

讀取properties配置檔案的幾種方法

方法一 properties props new properties props.load bugfactory.class.getresourceasstream xx.properties string name props.getpropery keyname 此時xx.properties...

讀取 properties配置檔案的幾種方式

這裡我將配置檔案放在src目錄下了,下面放的都是實驗過的 1 獲取到流檔案 fileinputstream is new fileinputstream src jdbc.properties 2 載入流檔案 properties properties new properties properti...