本篇内容主要讲解“Java Apollo环境的搭建以及集成SpringBoot的方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Java Apollo环境的搭建以及集成SpringBoot的方法”吧!
环境搭建
下载Quick Start安装包

从Github下载:checkout或下载apollo-build-scripts项目
手动打包Quick Start安装包
修改apollo-configservice, apollo-adminservice和apollo-portal的pom.xml,注释掉spring-boot-maven-plugin和maven-assembly-plugin
在根目录下执行mvn clean package -pl apollo-assembly -am -DskipTests=true
复制apollo-assembly/target下的jar包,rename为apollo-all-in-one.jar
创建数据库
Apollo服务端共需要两个数据库:ApolloPortalDB和ApolloConfigDB,数据库、表的相关Sql在安装包里,只需要导入数据库即可。直接导入就行。
配置数据库连接信息
-Apollo服务端需要知道如何连接到你前面创建的数据库,所以需要编辑demo.sh,修改ApolloPortalDB和ApolloConfigDB相关的数据库连接串信息。
注意:填入的用户需要具备对ApolloPortalDB和ApolloConfigDB数据的读写权限。
#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配置中心
./demo.sh start

Apollo启动成功


登录配置中心、新建服务的相关配置
apollo
admin
Apollo 集成 SpringBoot 读取配置文件
概述
Apollo支持API方式和Spring整合方式,该怎么选择用哪一种方式?
@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>
在配置中心新建配置文件

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


SpringBoot 配置拉去配置文件
apollo:
bootstrap:
eagerLoad:
enabled: true
enabled: true
namespaces: application,TEST1.ConfigOne
meta: http://localhost:8080
app:
id: app-demo-one-dev
到此,相信大家对“Java Apollo环境的搭建以及集成SpringBoot的方法”有了更深的了解,不妨来实际操作一番吧!这里是天达云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!