在眾多的設定中,如果將這些設定都集中在同一個設定檔則會太過混亂,所以有必要將某些設定進行切分,像是資料庫的連線設定就可以切分成另一個設定檔,如此要更動也比較容易。
從nacos新增一個設定檔(coupon命名空間)



切分好之後要在bootstrap.properties設定,讓這三個設定檔同時被載入

並且將application.yml內容註解掉,然後重啟服務測試
2020-11-22 15:39:51.256 INFO 1658 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-yumall-coupon.properties,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-yumall-coupon,DEFAULT_GROUP'}, BootstrapPropertySource {name='bootstrapProperties-other.yml,dev'}, BootstrapPropertySource {name='bootstrapProperties-mybatis.yml,dev'}, BootstrapPropertySource {name='bootstrapProperties-datasource.yml,dev'}]
從Console可以看到有載入剛剛新增的設定檔,然後打API測試,可以看到返回結果正常
http://127.0.0.1:7000/coupon/coupon/list
{
msg: "success",
code: 0,
page: {
totalCount: 0,
pageSize: 10,
totalPage: 0,
currPage: 1,
list: [ ]
}
}
這樣以後只需要在bootstrap.properties設定要載入哪些文件即可,而開發期間為了方便則繼續使用application.yml。
相關的nacos都可以參考官網連結