spring boot 讀取配置文件

需要兩步驟

1、在類上添加註解@PropertySource,指定配置文件路徑,默認路徑下可以不添加此註解(application.properties中的配置信息讀取就不需要此註解,直接第二步)

    classpath:con/myConfig.properties指的是src/main/resources目錄下con目錄下的myConfig.properties文件

@PropertySource({"classpath:config/my.properties","classpath:config/config.properties"})
public class TestController

2、在屬性名上添加@Value註解

@Value("${file.name}")
private String fileName;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章