springboot集成Apollo分布式配置
安裝Apollo服務
1.安裝mysql
地址:https://www.cnblogs.com/xuaa/p/10782352.html
2.下載Apollo源碼到本地
地址:https://github.com/ctripcorp/apollo
3.創建數據庫
創建configdb數據庫,數據庫腳本:apollo\scripts\db\migration\configdb\V1.0.0__initialization.sql
創建portaldb數據庫,數據庫腳本:apollo\scripts\db\migration\portaldb\V1.0.0__initialization.sql
4.修改打包腳本
腳本:apollo\scripts\build.bat
修改內容:
# 填寫ApolloConfigDB數據庫連接信息set apollo_config_db_url="jdbc:mysql://172.29.22.151:3306/ApolloConfigDB?characterEncoding=utf8"
set apollo_config_db_username="root"
set apollo_config_db_password="123456"
rem apollo portal db info
# 填寫ApolloPortalDB連接信息
set apollo_portal_db_url="jdbc:mysql://172.29.22.151:3306/ApolloPortalDB?characterEncoding=utf8"
set apollo_portal_db_username="root"
set apollo_portal_db_password="123456"
rem meta server url, different environments should have different meta server addresses
# 填寫meta服務準備安裝的服務地址,我只安裝了dev
set dev_meta="http://172.29.22.151:8080"
set fat_meta="http://172.29.22.151:8080"
set uat_meta="http://172.29.22.151:8080"
set pro_meta="http://172.29.22.151:8080"
?5.打包
在apollo\scripts目錄下cmd命令行界面執行build.bat腳本進行打包,打包完成后將以下文件上傳到Linux服務器
apollo\apollo-adminservice\target\apollo-adminservice-1.4.0-SNAPSHOT-github.zip
apollo\apollo-configservice\target\apollo-configservice-1.4.0-SNAPSHOT-github.zip
apollo\apollo-portal\target\apollo-portal-1.4.0-SNAPSHOT-github.zip
6.啟動
將第5步上傳的三個zip文件解壓,分別執行三個目錄下的啟動腳本scripts/startup.sh
?7.創建項目
訪問可視化界面,地址:http://172.29.22.151:8070,默認賬號/密碼:apollo/admin
創建項目
項目創建成功后點擊項目,添加配置信息
然后點擊發布
springboot客戶端集成apollo分布式配置
1.添加依賴
<dependency><groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.1.0</version>
</dependency>
2.修改application.properties
加入以下配置,注:app.id必須要和創建項目時填寫應用Id相同
app.id=elk-demoapollo.meta=http://172.29.22.151:8080
3.獲取配置信息
在Springboot項目啟動類中加入注解
@EnableApolloConfig通過注解獲取配置信息,注:111111為默認值
@Value("${test.name}")private String name;
或者 @Value("${test.name:111111}")
private String name;
轉載于:https://www.cnblogs.com/xuaa/p/10813163.html
總結
以上是生活随笔為你收集整理的springboot集成Apollo分布式配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: exit(0) exit(1) retu
- 下一篇: 美团笔试1--螺旋矩阵