SpringBoot 裡面讀取配置檔案 config.properties

首先 config。properties 放在resource 目錄下,內容以鍵值對文字儲存

SpringBoot 裡面讀取配置檔案 config.properties

程式碼中讀取方法

/** * 獲取配置資訊 */public static Configuration getConfig() { try { return new PropertiesConfiguration(“generator。properties” ); } catch (ConfigurationException e) { throw new RRException(“獲取配置檔案失敗,”, e); }}。。。//配置資訊Configuration config = getConfig();map。put(“package”, config。getString(“package” ));map。put(“moduleName”, config。getString(“moduleName” ));map。put(“author”, config。getString(“author” ));map。put(“email”, config。getString(“email” ));

2

如果把key value 直接放在 application。preperties 檔案裡面的話,也可以透過註解來取值;

SpringBoot 裡面讀取配置檔案 config.properties

直接透過註解方式獲取

import org。springframework。beans。factory。annotation。Value;@Value(“${ro。project。name}”)private String project_name;