-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: SpringValueProcessor extract duplicate code (#4137)
* refactor: SpringValueProcessor extract duplicate code * fix: typo & logging level
- Loading branch information
Showing
1 changed file
with
19 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
import com.google.common.collect.Multimap; | ||
import java.beans.PropertyDescriptor; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Member; | ||
import java.lang.reflect.Method; | ||
import java.util.Collection; | ||
import java.util.Set; | ||
|
@@ -46,7 +47,7 @@ | |
/** | ||
* Spring value processor of field or method which has @Value and xml config placeholders. | ||
* | ||
* @author github.com/zhegexiaohuozi [email protected] | ||
* @author github.com/zhegexiaohuozi [email protected] [email protected] | ||
* @since 2017/12/20. | ||
*/ | ||
public class SpringValueProcessor extends ApolloProcessor implements BeanFactoryPostProcessor, BeanFactoryAware { | ||
|
@@ -94,17 +95,8 @@ protected void processField(Object bean, String beanName, Field field) { | |
if (value == null) { | ||
return; | ||
} | ||
Set<String> keys = placeholderHelper.extractPlaceholderKeys(value.value()); | ||
|
||
if (keys.isEmpty()) { | ||
return; | ||
} | ||
|
||
for (String key : keys) { | ||
SpringValue springValue = new SpringValue(key, value.value(), bean, beanName, field, false); | ||
springValueRegistry.register(beanFactory, key, springValue); | ||
logger.debug("Monitoring {}", springValue); | ||
} | ||
doRegister(bean, beanName, field, value); | ||
} | ||
|
||
@Override | ||
|
@@ -124,20 +116,33 @@ protected void processMethod(Object bean, String beanName, Method method) { | |
return; | ||
} | ||
|
||
Set<String> keys = placeholderHelper.extractPlaceholderKeys(value.value()); | ||
doRegister(bean, beanName, method, value); | ||
} | ||
|
||
private void doRegister(Object bean, String beanName, Member member, Value value) { | ||
Set<String> keys = placeholderHelper.extractPlaceholderKeys(value.value()); | ||
if (keys.isEmpty()) { | ||
return; | ||
} | ||
|
||
for (String key : keys) { | ||
SpringValue springValue = new SpringValue(key, value.value(), bean, beanName, method, false); | ||
SpringValue springValue; | ||
if (member instanceof Field) { | ||
Field field = (Field) member; | ||
springValue = new SpringValue(key, value.value(), bean, beanName, field, false); | ||
} else if (member instanceof Method) { | ||
Method method = (Method) member; | ||
springValue = new SpringValue(key, value.value(), bean, beanName, method, false); | ||
} else { | ||
logger.error("Apollo @Value annotation currently only support to be used on methods and fields, " | ||
+ "but is used on {}", member.getClass()); | ||
return; | ||
} | ||
springValueRegistry.register(beanFactory, key, springValue); | ||
logger.info("Monitoring {}", springValue); | ||
} | ||
} | ||
|
||
|
||
private void processBeanPropertyValues(Object bean, String beanName) { | ||
Collection<SpringValueDefinition> propertySpringValues = beanName2SpringValueDefinitions | ||
.get(beanName); | ||
|