Skip to content

Commit

Permalink
Apollo 多环境示例
Browse files Browse the repository at this point in the history
  • Loading branch information
YunaiV committed Jan 27, 2020
1 parent 752dae2 commit 9c4cb09
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
## 配置中心

* [《芋道 Spring Boot 配置文件》](http://www.iocoder.cn/Spring-Boot/config-file/?github) 对应 [lab-43](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-43)
* [《芋道 Spring Boot 配置中心 Apollo》]()计划中...
* [《芋道 Spring Boot 配置中心 Apollo》](http://www.iocoder.cn/Spring-Boot/config-apollo/?github) 对应 [lab-45](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-45)
* [《芋道 Spring Boot 配置中心 Nacos》](http://www.iocoder.cn/Spring-Boot/config-nacos/?github) 对应 [lab-44](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-44)

## 注册中心
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public class ValueCommandLineRunner implements CommandLineRunner {
@Value(value = "${order.pay-timeout-seconds}")
private Integer payTimeoutSeconds;

// @NacosValue(value = "${order.pay-timeout-seconds}")
@Value(value = "${order.pay-timeout-seconds}")
// @NacosValue(value = "${order.create-frequency-seconds}")
@Value(value = "${order.create-frequency-seconds}")
private Integer createFrequencySeconds;

@Override
Expand Down
31 changes: 31 additions & 0 deletions lab-45/lab-45-apollo-demo-profiles/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>lab-45-apollo-demo-profiles</artifactId>


<dependencies>
<!-- 实现对 SpringMVC 的自动化配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- 引入 Apollo 客户端,内置对 Apollo 的自动化配置 -->
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.5.1</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cn.iocoder.springboot.lab45.apollodemo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ProfilesApplication {

public static void main(String[] args) {
SpringApplication.run(ProfilesApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
app:
id: demo-application-profiles # 使用的 Apollo 的项目(应用)编号
apollo:
meta: http://127.0.0.1:8080 # Apollo Meta Server 地址
bootstrap:
enabled: true # 是否开启 Apollo 配置预加载功能。默认为 false。
eagerLoad:
enable: true # 是否开启 Apollo 支持日志级别的加载时机。默认为 false。
namespaces: application # 使用的 Apollo 的命名空间,默认为 application。
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
app:
id: demo-application-profiles # 使用的 Apollo 的项目(应用)编号
apollo:
meta: http://127.0.0.1:18080 # Apollo Meta Server 地址
bootstrap:
enabled: true # 是否开启 Apollo 配置预加载功能。默认为 false。
eagerLoad:
enable: true # 是否开启 Apollo 支持日志级别的加载时机。默认为 false。
namespaces: application # 使用的 Apollo 的命名空间,默认为 application。
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#server:
# port: 7070

spring:
application:
name: demo-application
2 changes: 1 addition & 1 deletion lab-45/lab-45-apollo-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<artifactId>spring-boot-starter</artifactId>
</dependency>

<!-- 实现对 Nacos 作为配置中心的自动化配置 TODO -->
<!-- 引入 Apollo 客户端,内置对 Apollo 的自动化配置 -->
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ public class ValueCommandLineRunner implements CommandLineRunner {

private final Logger logger = LoggerFactory.getLogger(getClass());

// @NacosValue(value = "${order.pay-timeout-seconds}")
@Value(value = "${order.pay-timeout-seconds}")
private Integer payTimeoutSeconds;

// @NacosValue(value = "${order.pay-timeout-seconds}")
@Value(value = "${order.pay-timeout-seconds}")
@Value(value = "${order.create-frequency-seconds}")
private Integer createFrequencySeconds;

@Override
Expand Down
10 changes: 5 additions & 5 deletions lab-45/lab-45-apollo-demo/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
app:
id: demo-application
id: demo-application # 使用的 Apollo 的项目(应用)编号
apollo:
meta: http://127.0.0.1:8080
meta: http://127.0.0.1:8080 # Apollo Meta Server 地址
bootstrap:
enabled: true
enabled: true # 是否开启 Apollo 配置预加载功能。默认为 false。
eagerLoad:
enable: true
namespace: application
enable: true # 是否开启 Apollo 支持日志级别的加载时机。默认为 false。
namespaces: application # 使用的 Apollo 的命名空间,默认为 application。
1 change: 1 addition & 0 deletions lab-45/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<packaging>pom</packaging>
<modules>
<module>lab-45-apollo-demo</module>
<module>lab-45-apollo-demo-profiles</module>
</modules>


Expand Down

0 comments on commit 9c4cb09

Please sign in to comment.