1. 程式人生 > >spring boot 新增自定義配置檔案並讀取屬性

spring boot 新增自定義配置檔案並讀取屬性

"123"
"pcq"

spring 屬性檔案預設配置檔案是從application.properties讀取的,

但是我想把配置檔案分開,比如 業務的我想放在biz.properties, 客戶端配置的放在client.properties ,

但是注入呢,經過測試可以這麼做

比如

//多個配置檔案
@PropertySource("classpath:biz.properties")
@Controller
public class UserService {
    //來自 application.properties
    @Value("${name}")
    private String name;
    //來自biz.properties
    @Value("${biz}")
    private String biz;
    @RequestMapping("/test")
    public void test(){
        System.out.println(biz);
        System.out.println(name);
    }
}

biz.properties 內容如下

biz="biz"
結果:

"123"
"pcq"