欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java Apollo環(huán)境搭建以及集成SpringBoot案例詳解

 更新時間:2021年08月30日 14:21:34   作者:MarlonBrando1998  
這篇文章主要介紹了Java Apollo環(huán)境搭建以及集成SpringBoot案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下

環(huán)境搭建

下載Quick Start安裝包

請?zhí)砑訄D片描述

從Github下載:checkout或下載apollo-build-scripts項目

手動打包Quick Start安裝包

  • 修改apollo-configservice, apollo-adminservice和apollo-portal的pom.xml,注釋掉spring-boot-maven-plugin和maven-assembly-plugin
  • 在根目錄下執(zhí)行mvn clean package -pl apollo-assembly -am -DskipTests=true
  • 復(fù)制apollo-assembly/target下的jar包,rename為apollo-all-in-one.jar

創(chuàng)建數(shù)據(jù)庫

Apollo服務(wù)端共需要兩個數(shù)據(jù)庫:ApolloPortalDB和ApolloConfigDB,數(shù)據(jù)庫、表的相關(guān)Sql在安裝包里,只需要導(dǎo)入數(shù)據(jù)庫即可。直接導(dǎo)入就行。

配置數(shù)據(jù)庫連接信息

-Apollo服務(wù)端需要知道如何連接到你前面創(chuàng)建的數(shù)據(jù)庫,所以需要編輯demo.sh,修改ApolloPortalDB和ApolloConfigDB相關(guān)的數(shù)據(jù)庫連接串信息。

注意:填入的用戶需要具備對ApolloPortalDB和ApolloConfigDB數(shù)據(jù)的讀寫權(quán)限。

#apollo config db info
apollo_config_db_url=jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8
apollo_config_db_username=用戶名
apollo_config_db_password=密碼(如果沒有密碼,留空即可)

# apollo portal db info
apollo_portal_db_url=jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8
apollo_portal_db_username=用戶名
apollo_portal_db_password=密碼(如果沒有密碼,留空即可)

注意:不要修改demo.sh的其它部分

修改默認的apollo端口

# meta server url
config_server_url=http://localhost:6001
admin_server_url=http://localhost:6002
eureka_service_url=$config_server_url/eureka/
portal_url=http://localhost:6003

啟動apollo配置中心

  • 在 git bash窗口中運行命令行
./demo.sh start
  • 啟動成功界面信息如下:

請?zhí)砑訄D片描述

  • 如果啟動報錯,請在相應(yīng)的日志文件中查看出錯原因。

Apollo啟動成功

  • 默認8080界面

請?zhí)砑訄D片描述

  • 8090 apoolo配置界面

請?zhí)砑訄D片描述

登錄配置中心、新建服務(wù)的相關(guān)配置

  • 默認賬號密碼:
apollo
admin

Apollo 集成 SpringBoot 讀取配置文件

概述

Apollo支持API方式和Spring整合方式,該怎么選擇用哪一種方式?

  • API方式靈活,功能完備,配置值實時更新(熱發(fā)布),支持所有Java環(huán)境。
  • Spring方式接入簡單。 Spring方式也可以結(jié)合API方式使用,如注入Apollo的Config對象,就可以照常通過API方式獲取配置了:
@ApolloConfig
private Config config; //inject config for namespace application

引入依賴

<dependency>
	<groupId>com.ctrip.framework.apollo</groupId>
	<artifactId>apollo-client</artifactId>
	<version>1.3.0</version>
</dependency>

在配置中心新建配置文件

請?zhí)砑訄D片描述

配置私有的 app-demo-one-dev 和共有的 app-common-dev

  • app-demo-one-dev私有配置

請?zhí)砑訄D片描述

  • app-common-dev 共有配置

請?zhí)砑訄D片描述

SpringBoot 配置拉去配置文件

  • application.yml
apollo:
  bootstrap:
    eagerLoad:
      enabled: true
    enabled: true
    namespaces: application,TEST1.ConfigOne
  meta: http://localhost:8080
app:
  id: app-demo-one-dev

到此這篇關(guān)于Java Apollo環(huán)境搭建以及集成SpringBoot案例詳解的文章就介紹到這了,更多相關(guān)Java Apollo環(huán)境搭建以及集成SpringBoot內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論