spring.datasource.url = jdbc:mysql://localhost:3306/ApolloConfigDB?useSSL=false&characterEncoding=utf8

spring.datasource.username = someuser

spring.datasource.password = somepwd

2.配置apollo-adminservice的数据库连接信息

用程序员专用编辑器(如vim,notepad++,sublime等)打开config目录下的application-github.properties文件,修改完的效果如下:

DataSource

spring.datasource.url = jdbc:mysql://localhost:3306/ApolloConfigDB?useSSL=false&characterEncoding=utf8

spring.datasource.username = someuser

spring.datasource.password = somepwd

3.配置apollo-portal的数据库连接信息

用程序员专用编辑器(如vim,notepad++,sublime等)打开config目录下的application-github.properties文件,修改完的效果如下:

local.meta=http://localhost:8080

#dev.meta=http://fill-in-dev-meta-server:8080

#fat.meta=http://fill-in-fat-meta-server:8080

#uat.meta=http://fill-in-uat-meta-server:8080

#lpt.meta=${lpt_meta}

pro.meta=http://localhost:8080

DataSource

spring.datasource.url = jdbc:mysql://localhost:3306/ApolloPortalDB?useSSL=false&characterEncoding=utf8

spring.datasource.username = someuser

spring.datasource.password = somepwd

4.配置apollo-portal的meta service信息

使用程序员专用编辑器(如vim,notepad++,sublime等)打开apollo-portal-x.x.x-github.zip中config目录下的apollo-env.properties文件。修改完的效果如下:

local.meta=http://localhost:8080

pro.meta=http://localhost:8080

5.运行

导入服务器运行scripts/startup.sh

6.整合spring boot

1.修改pom文件

<dependency>

<groupId>com.ctrip.framework.apollo</groupId>

<artifactId>apollo-client</artifactId>

<version>1.3.0</version>

</dependency>

2.修改application配置

app:

id: 项目名称

apollo:

meta: http://127.0.0.1:8080(admin server 端口默认8080)

bootstrap:

enabled: true

eagerLoad:

enabled: true

3.SpringBootApplication加入注解

@EnableApolloConfig

6.页面配置

1.新建项目

在这里插入图片描述

在这里插入图片描述

红圈处为上面配置的组织名。

2.处理项目的配置项

在这里插入图片描述

在这里插入图片描述也可以直接输入全部配置项。

在这里插入图片描述

更改配置之后需要点击发布,否则不会更改。

在这里插入图片描述

7.验证

对于项目来说,因为配置放入了applicationcontent中,所以需要重启才能生效,但是通过以下代码不重启就能体现出生效。

@RestController

public class HelloController {

@Value("${server.port}")

String port;

@GetMapping("hi")

public String hi(String name) {

return "hi " + name + " ,i am from port:" + port;

}

}

本次面试答案,以及收集到的大厂必问面试题分享:

字节跳动超高难度三面java程序员面经,大厂的面试都这么变态吗?