pull/1463/head
shedfreewu 10 months ago
parent 484bb07b6b
commit b31ce01adf

@ -149,6 +149,9 @@ public class SpringValueProcessor extends PolarisProcessor implements BeanDefini
/**
* @RefreshScope on method.
* method parameter with @Value ${@link com.tencent.cloud.polaris.config.spring.annotation.RefreshScopeSpringProcessorTest.TestConfig3#testBean3}.
* method parameter class with @ConfigurationProperties ${@link com.tencent.cloud.polaris.config.spring.annotation.RefreshScopeSpringProcessorTest.TestConfig4#testBean4}.
* @ConfigurationProperties outside method may effect @RefreshScope bean${@link com.tencent.cloud.polaris.config.spring.annotation.RefreshScopeSpringProcessorTest.TestConfig5#testBean5()}.
* @param bean spring bean.
* @param method method.
*/
@ -205,9 +208,15 @@ public class SpringValueProcessor extends PolarisProcessor implements BeanDefini
}
/**
* parse refresh scope keys from @ConfigurationProperties and prefix.
* @param configClazz class of @ConfigurationProperties bean.
* @param prefix config prefix.
* parse all fields of the configClazz.
* if the field is primitive or wrapper, add it to refresh scope key map.
* ${@link com.tencent.cloud.polaris.config.spring.annotation.RefreshScopeSpringProcessorTest.TestBeanProperties2#name}
* if the field is collection, add it to refresh scope prefix trie node.
* ${@link com.tencent.cloud.polaris.config.spring.annotation.RefreshScopeSpringProcessorTest.TestBeanProperties2#list}
* if the field is complex type, recursive parse.
* ${@link com.tencent.cloud.polaris.config.spring.annotation.RefreshScopeSpringProcessorTest.TestBeanProperties2#inner}
* @param configClazz class or subclass of @ConfigurationProperties bean.
* @param prefix prefix or subclass's prefix of @ConfigurationProperties bean.
*/
private void parseConfigKeys(Class<?> configClazz, String prefix) {
for (Field field : findAllField(configClazz)) {

@ -131,6 +131,11 @@ public class SpringValueRegistry implements DisposableBean {
refreshScopeKeys.addAll(keys);
}
/**
* first check if the key is in refreshScopeKeys, if not, check the key by TrieUtil.
* @param key changed key.
* @return true if the key is refresh scope key, otherwise false.
*/
public boolean isRefreshScopeKey(String key) {
if (refreshScopeKeys.contains(key)) {
return true;

@ -211,7 +211,9 @@ public class RefreshScopeSpringProcessorTest {
@Bean
@RefreshScope
public TestBean testBean5() {
return new TestBean();
TestBean testBean = new TestBean();
testBean.setName(testBeanProperties2.getName());
return testBean;
}
}

Loading…
Cancel
Save