• Apollo分布式配置中心入门学习


    一、Apollo地址

    Apollo源码及简介Apollo配置中心Apollo设计原理
    java使用指南

    二、Apollo环境搭建

    1、下载配置中心
    2、执行两个sql文件:apolloconfigdb(存放配置文件信息)、apolloportaldb(网站信息)
    3、下载好的apollo-build-scripts-master上传到服务器。服务器需要JDK环境
    4、解压:unzip apollo-build-scripts-master.zip 
    5、进入/apollo-build-scripts-master修改demo.sh。修改数据库信息,配置服务地址。
    

    在这里插入图片描述

    6、./demo.sh start  启动服务
    

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    7、默认账号:apollo,密码:admin
    8、创建项目
    

    在这里插入图片描述

    9、日志可以在servicewe文件夹下面的.log里面查看
    

    三、整合Springboot

    • Maven
        <dependency>
            <groupId>com.ctrip.framework.apollo</groupId>
            <artifactId>apollo-client</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.ctrip.framework.apollo</groupId>
            <artifactId>apollo-core</artifactId>
            <version>1.0.0</version>
        </dependency>
    

    这里引入的jar下载下来好像不可以使用。需要我们手动下载Apollo然后编译导入Maven仓库
    1、先删除Maven仓库已有的apollo jar
    2、apollo-masterscripts
    在这里插入图片描述

    3.点击build.bat,等命令行执行完成之后就可以看到Maven仓库中的jar包了
    
    • 入口文件
    @SpringBootApplication
    @EnableApolloConfig
    public class ApolloApplication {
        public static void main(String[] args) {
            SpringApplication.run(ApolloApplication.class,args);
        }
    }
    
    • application.yml
    server:
      port: 8001
    spring:
      application:
        name: springboot-abl
    
    • 配置apollo
    apollo.meta=http://192.168.100.128:8080
    #应用ID
    app.id=test
    
    

    除了可以在配置文件配置之外,还有如下配置方法
    1.通过Java System Property 在java的启动脚本中,在VM options中指定 -Dapollo.meta= http://config-service-url
    2.通过Spring Boot的配置文件在application.properties或bootstrap.properties文件中指定apollo.meta=http://config-service-url
    3.通过在操作系统中的server.properties配置文件Windows中,文件位置为C:optsettingsserver.properties,在其中配置apollo.meta=http://config-service-url
    4.通过在app.properties配置文件中指定apollo.meta=http://config-service-url

    在这里插入图片描述

    • Controller
    @RestController
    public class IndexController {
        //:后面相当于是默认值
        @Value("${test:test}")
        private String test;
    
        @GetMapping("/apolloDemo")
        public String getYushengjun() {
            return test;
        }
    
    }
    
    
    • 环境(Environment)
      指定程序的运行环境,这里配置为DEV 也就是开发环境。介绍常用的几种配置方式:
      1.通过Java System Property 在java的启动脚本,在VM options中指定-Denv=DEV
      2.通过系统的配置文件 在C:optsettingsserver.properties中配置env=DEV
    • 启动
      在这里插入图片描述

    此时访问:
    在这里插入图片描述

    在apollo发布配置
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    在apollo发布过的配置文件,在本地也会有一份
    C:optdata目录下面找到APPID对应的文件就可以看到了。
    在这里插入图片描述

  • 相关阅读:
    每日总结2021.9.14
    jar包下载mvn
    每日总结EL表达语言 JSTL标签
    每日学习总结之数据中台概述
    Server Tomcat v9.0 Server at localhost failed to start
    Server Tomcat v9.0 Server at localhost failed to start(2)
    链表 java
    MVC 中用JS跳转窗体Window.Location.href
    Oracle 关键字
    MVC 配置路由 反复走控制其中的action (int?)
  • 原文地址:https://www.cnblogs.com/yangk1996/p/12656633.html
Copyright © 2020-2023  润新知