Skip to content

Commit 62762f8

Browse files
author
Joey Yang
committed
update springboot version, fix path matching bug in springboot 2.2
1 parent f0d1aab commit 62762f8

File tree

7 files changed

+10
-35
lines changed

7 files changed

+10
-35
lines changed

README-zh.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ Maven
4242
<dependency>
4343
<groupId>top.code2life</groupId>
4444
<artifactId>spring-boot-dynamic-config</artifactId>
45-
<version>1.0.7</version>
45+
<version>1.0.8</version>
4646
</dependency>
4747
```
4848

4949
Gradle
5050

5151
```groovy
52-
implementation 'top.code2life:spring-boot-dynamic-config:1.0.7'
52+
implementation 'top.code2life:spring-boot-dynamic-config:1.0.8'
5353
```
5454

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

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ Maven
4242
<dependency>
4343
<groupId>top.code2life</groupId>
4444
<artifactId>spring-boot-dynamic-config</artifactId>
45-
<version>1.0.7</version>
45+
<version>1.0.8</version>
4646
</dependency>
4747
```
4848

4949
Gradle
5050

5151
```groovy
52-
implementation 'top.code2life:spring-boot-dynamic-config:1.0.7'
52+
implementation 'top.code2life:spring-boot-dynamic-config:1.0.8'
5353
```
5454

5555
### Step2. Add @DynamicConfig Annotation

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
buildscript {
22
ext {
3-
springBootVersion = '2.4.5'
3+
springBootVersion = '2.5.4'
44
}
55
}
66
plugins {
@@ -16,7 +16,7 @@ java {
1616
}
1717

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

2222
repositories {

example/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ dependencies {
2727
annotationProcessor 'org.projectlombok:lombok:1.18.20'
2828
implementation 'org.springframework.boot:spring-boot-starter-web'
2929

30-
implementation 'top.code2life:spring-boot-dynamic-config:1.0.7'
30+
implementation 'top.code2life:spring-boot-dynamic-config:1.0.8'
3131
}

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Wed May 19 22:12:06 CST 2021
2-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
2+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
33
distributionBase=GRADLE_USER_HOME
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static String trimRelativePathAndReplaceBackSlash(String str) {
8484
if (beginWithRelative) {
8585
return str.substring(2).replaceAll("\\\\", "/");
8686
}
87-
return str;
87+
return str.replaceAll("\\\\", "/");
8888
}
8989

9090

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

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import org.springframework.beans.factory.config.BeanPostProcessor;
66
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
77
import org.springframework.boot.context.properties.ConfigurationProperties;
8-
import org.springframework.context.ApplicationContext;
98
import org.springframework.util.StringUtils;
109

11-
import javax.annotation.PostConstruct;
1210
import java.lang.reflect.Field;
1311
import java.util.ArrayList;
1412
import java.util.Collections;
@@ -32,30 +30,12 @@ public class DynamicConfigBeanPostProcessor implements BeanPostProcessor {
3230

3331
static final Map<String, List<ValueBeanFieldBinder>> DYNAMIC_FIELD_BINDER_MAP = new ConcurrentHashMap<>(16);
3432
static final Map<String, ValueBeanFieldBinder> DYNAMIC_CONFIG_PROPS_BINDER_MAP = new ConcurrentHashMap<>(8);
35-
static final Map<String, Object> DYNAMIC_BEAN_MAP = new ConcurrentHashMap<>(16);
3633

37-
private final ApplicationContext applicationContext;
38-
39-
DynamicConfigBeanPostProcessor(ApplicationContext applicationContext) {
40-
this.applicationContext = applicationContext;
41-
DYNAMIC_BEAN_MAP.clear();
34+
DynamicConfigBeanPostProcessor() {
4235
DYNAMIC_FIELD_BINDER_MAP.clear();
4336
DYNAMIC_CONFIG_PROPS_BINDER_MAP.clear();
4437
}
4538

46-
/**
47-
* Check all beans with DynamicConfig annotation after this PostProcessor being initialized,
48-
* this double check mechanism is for a special case: some beans created by other approaches directly, not calling BeanPostProcessor
49-
*/
50-
@PostConstruct
51-
public void handleDynamicConfigurationBeans() {
52-
Map<String, Object> dynamicBeans = applicationContext.getBeansWithAnnotation(DynamicConfig.class);
53-
for (Map.Entry<String, Object> entry : dynamicBeans.entrySet()) {
54-
String beanName = entry.getKey();
55-
handleDynamicBean(entry.getValue(), beanName);
56-
}
57-
}
58-
5939
/**
6040
* Process all beans contains @DynamicConfig annotation, collect metadata for continuous field value binding
6141
*
@@ -70,11 +50,6 @@ public Object postProcessAfterInitialization(Object bean, String beanName) {
7050
}
7151

7252
private void handleDynamicBean(Object bean, String beanName) {
73-
// avoid duplicate processing after post processor
74-
if (DYNAMIC_BEAN_MAP.containsKey(beanName)) {
75-
return;
76-
}
77-
DYNAMIC_BEAN_MAP.putIfAbsent(beanName, bean);
7853
Class<?> clazz = ConfigurationUtils.getTargetClassOfBean(bean);
7954
Field[] fields = clazz.getDeclaredFields();
8055
// handle @ConfigurationProperties beans

0 commit comments

Comments
 (0)