Apollo源码阅读(一)环境搭建

805 阅读1分钟

一、工程搭建

1、下载工程

2、执行数据库脚本

数据库脚本路径:

3、启动ConfigService和AdminService

  • 启动入口:com.ctrip.framework.apollo.assembly.ApolloApplication
  • VM options:
-Dapollo_profile=github
-Deureka.service.url=http://localhost:8080/eureka/
-Dspring.datasource.url=jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8
-Dspring.datasource.username=root
-Dspring.datasource.password=
-Dlogging.file=/path/apollo.log
  • Program arguments:--configservice --adminservice

  • ApolloApplication根据启动参数启动了configservice和adminservice

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,
    HibernateJpaAutoConfiguration.class})
public class ApolloApplication {
  public static void main(String[] args) throws Exception {
    // Common
    ConfigurableApplicationContext commonContext =
        new SpringApplicationBuilder(ApolloApplication.class).web(WebApplicationType.NONE).run(args);
    // ConfigService
    if (commonContext.getEnvironment().containsProperty("configservice")) {
      ConfigurableApplicationContext configContext =
          new SpringApplicationBuilder(ConfigServiceApplication.class).parent(commonContext)
              .sources(RefreshScope.class).run(args);
    }
    //AdminService
    if (commonContext.getEnvironment().containsProperty("adminservice")) {
      ConfigurableApplicationContext adminContext =
          new SpringApplicationBuilder(AdminServiceApplication.class).parent(commonContext)
              .sources(RefreshScope.class).run(args);
    }
  }
}

4、启动Portal

  • 启动入口:com.ctrip.framework.apollo.portal.PortalApplication
  • VM options:
-Ddev_meta=http://localhost:8080/
-Dserver.port=8070
-Dspring.datasource.url=jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8
-Dspring.datasource.username=root
-Dspring.datasource.password=
-Dapollo_profile=github,auth

5、登录Portal,配置测试数据

  • 首页: http://localhost:8070/
  • 用户名/密码:portal/admin
  • 给SampleApp新增配置,之后用官方SpringBootDemo需要这些配置参数
timeout = 2000
redis.cache.enabled = true
redis.cache.expireSeconds = 100
redis.cache.clusterNodes = 1,2
redis.cache.commandTimeout = 50
redis.cache.someMap.key1 = a
redis.cache.someMap.key2 = b
redis.cache.someList[0] = c
redis.cache.someList[1] = d

6、启动官方SpringBoot样例应用

  • 入口:com.ctrip.framework.apollo.demo.spring.springBootDemo.SpringBootSampleApplication
  • 启动后在控制台随便输入字符串,打印出两行配置