Skip to content

Commit fd3cc92

Browse files
author
Joey Yang
committed
add more test case, use jacoco coverage, fix leaf map value not deleted issue
1 parent 4a233cf commit fd3cc92

File tree

14 files changed

+348
-52
lines changed

14 files changed

+348
-52
lines changed

.github/workflows/gradle.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ jobs:
2626
OSSRHUSERNAME: ${{ secrets.OSSRHUSERNAME }}
2727
OSSRHPASSWORD: ${{ secrets.OSSRHPASSWORD }}
2828
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
29-
- uses: codecov/codecov-action@v1
29+
- name: codecov report
30+
uses: codecov/codecov-action@v1
3031
with:
3132
token: ${{ secrets.CODECOV_TOKEN }}
3233
files: build/reports/jacoco/report.xml
33-
verbose: true
34+
verbose: true
35+
- name: jacoco-badge
36+
uses: cicirello/jacoco-badge-generator@v2
37+
with:
38+
generate-branches-badge: true
39+
jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv

README-zh.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<p align="center">
22
<a href="https://github.com/code2life/spring-boot-dynamic-config"><img src="https://github.com/code2life/spring-boot-dynamic-config/actions/workflows/gradle.yml/badge.svg" /></a>
3-
<a href="https://codecov.io/gh/code2life/spring-boot-dynamic-config/"><img src="https://img.shields.io/codecov/c/github/code2life/spring-boot-dynamic-config/main.svg" alt="Coverage Status"></a>
3+
<a href="https://github.com/code2life/spring-boot-dynamic-config/actions/workflows/gradle.yml">coverage<img src=".github/badges/jacoco.svg" /></a>
44
<a href="https://codebeat.co/projects/git.colasdn.top-code2life-spring-boot-dynamic-config-main"><img alt="codebeat badge" src="https://codebeat.co/badges/ea7b2127-62f3-45f4-9f38-55f8203c0121" /></a>
55
</p>
66

@@ -13,6 +13,7 @@
1313
- :heart: **无侵入**,完全兼容SpringBoot原生的配置获取方式(@Value / @ConfigurationProperties
1414
- :zap: **超轻量,超快响应**, 不依赖SpringBoot核心库以外的任何三方库
1515
- :grinning: **极易使用**, 只提供一个简单的注解: @DynamicConfig;一个事件:ConfigurationChangedEvent
16+
- ☸ 在K8S集群中运行SpringBoot/SpringCloud应用,与K8S ConfigMap完美结合的方案
1617

1718
#### 相比于spring-cloud-starter-config:
1819

@@ -37,14 +38,14 @@ Maven
3738
<dependency>
3839
<groupId>top.code2life</groupId>
3940
<artifactId>spring-boot-dynamic-config</artifactId>
40-
<version>1.0.1</version>
41+
<version>1.0.4</version>
4142
</dependency>
4243
```
4344

4445
Gradle
4546

4647
```groovy
47-
implementation 'top.code2life:spring-boot-dynamic-config:1.0.1'
48+
implementation 'top.code2life:spring-boot-dynamic-config:1.0.4'
4849
```
4950

5051
### 步骤二:在代码中添加 @DynamicConfig 注解

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<p align="center">
22
<a href="https://github.com/code2life/spring-boot-dynamic-config"><img src="https://github.com/code2life/spring-boot-dynamic-config/actions/workflows/gradle.yml/badge.svg" /></a>
3-
<a href="https://codecov.io/gh/code2life/spring-boot-dynamic-config/"><img src="https://img.shields.io/codecov/c/github/code2life/spring-boot-dynamic-config/main.svg" alt="Coverage Status"></a>
3+
<a href="https://github.com/code2life/spring-boot-dynamic-config/actions/workflows/gradle.yml">coverage<img src=".github/badges/jacoco.svg" /></a>
44
<a href="https://codebeat.co/projects/git.colasdn.top-code2life-spring-boot-dynamic-config-main"><img alt="codebeat badge" src="https://codebeat.co/badges/ea7b2127-62f3-45f4-9f38-55f8203c0121" /></a>
55
</p>
66

@@ -13,6 +13,7 @@ Hot-reload your SpringBoot configurations, with just a '@DynamicConfig' annotati
1313
- :heart: **Non-intrusive**, compatible with SpringBoot native ways (@Value, @ConfigurationProperties)
1414
- :zap: **Lightweight & Blazing Fast**, depend on nothing but SpringBoot core libs
1515
- :grinning: **Extremely easy to use**, only provide an annotation: @DynamicConfig, an event: ConfigurationChangedEvent
16+
- ☸ Perfect solution for running SpringBoot on Kubernetes, combine with K8S ConfigMap
1617

1718

1819
#### Compare with spring-cloud-starter-config
@@ -36,14 +37,14 @@ Maven
3637
<dependency>
3738
<groupId>top.code2life</groupId>
3839
<artifactId>spring-boot-dynamic-config</artifactId>
39-
<version>1.0.1</version>
40+
<version>1.0.4</version>
4041
</dependency>
4142
```
4243

4344
Gradle
4445

4546
```groovy
46-
implementation 'top.code2life:spring-boot-dynamic-config:1.0.1'
47+
implementation 'top.code2life:spring-boot-dynamic-config:1.0.4'
4748
```
4849

4950
### Step2. Add @DynamicConfig Annotation

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ java {
1616
}
1717

1818
group = 'top.code2life'
19-
version = '1.0.3'
19+
version = '1.0.4'
2020
sourceCompatibility = JavaVersion.VERSION_1_8
2121

2222
repositories {
@@ -111,7 +111,7 @@ jacocoTestReport {
111111
reports {
112112
xml.enabled true
113113
xml.destination file("${buildDir}/reports/jacoco/report.xml")
114-
csv.enabled false
114+
csv.enabled true
115115
html.enabled true
116116
html.destination layout.buildDirectory.dir('jacocoHtml').get().asFile
117117
}

example/src/main/java/com/example/demo/DemoConfigProperties.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import org.springframework.core.annotation.Order;
88
import top.code2life.config.DynamicConfig;
99

10+
import java.util.List;
11+
import java.util.Map;
12+
1013
/**
1114
* @author Code2Life
1215
**/
@@ -18,4 +21,13 @@ public class DemoConfigProperties {
1821

1922
private String str;
2023

24+
private Map<String, String> mapVal;
25+
26+
private List<Integer> listVal;
27+
28+
private List<DemoConfigProperties> nestedList;
29+
30+
private Map<String, DemoConfigProperties> nestedMap;
31+
32+
private DemoConfigProperties nested;
2133
}

example/src/main/java/com/example/demo/DemoController.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,15 @@ public class DemoController {
3030
private final FeatureGate featureGate;
3131

3232
@RequestMapping(value = "/demo", method = RequestMethod.GET)
33-
public String getDemoConfigProps() {
34-
return demoConfigProps.getStr();
33+
public Object getDemoConfigProps() {
34+
DemoConfigProperties resp = new DemoConfigProperties();
35+
resp.setStr(demoConfigProps.getStr());
36+
resp.setListVal(demoConfigProps.getListVal());
37+
resp.setMapVal(demoConfigProps.getMapVal());
38+
resp.setNestedList(demoConfigProps.getNestedList());
39+
resp.setNestedMap(demoConfigProps.getNestedMap());
40+
resp.setNested(demoConfigProps.getNested());
41+
return resp;
3542
}
3643

3744
@RequestMapping(value = "/demo2", method = RequestMethod.GET)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.example.demo;
2+
3+
/**
4+
* @author Code2Life
5+
**/
6+
public class DemoSubConfig {
7+
}
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
11
dynamic:
22
prop:
3-
str: abcdeeffgggaa
3+
str: hello
4+
map-val:
5+
k1: v1
6+
k2: v2
7+
list-val:
8+
- 1
9+
- 2
10+
- 3
11+
nested-list:
12+
- str: hello-inner
13+
map-val:
14+
k2-inner: v1-inner
15+
nested_map:
16+
m1:
17+
str: hello-map
18+
list-val: [5,6,7]
19+
20+
nested:
21+
str: hello-recursive-1
22+
map-val:
23+
x1: y1

src/main/java/top/code2life/config/DynamicConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* The annotation @DynamicConfig could be added on Class or Field level,
99
* to indicate that all @Value fields or single @Value field is dynamic loaded,
1010
* which means the actual value changes upon configuration file changes.
11+
* The processor of this annotation is not thread-safe, when configuration changes,
12+
* it will modify fields of the corresponding bean, during the period, dirty value could exist.
1113
*
1214
* Example:
1315
*

0 commit comments

Comments
 (0)