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. * @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 bean spring bean.
* @param method method. * @param method method.
*/ */
@ -205,9 +208,15 @@ public class SpringValueProcessor extends PolarisProcessor implements BeanDefini
} }
/** /**
* parse refresh scope keys from @ConfigurationProperties and prefix. * parse all fields of the configClazz.
* @param configClazz class of @ConfigurationProperties bean. * if the field is primitive or wrapper, add it to refresh scope key map.
* @param prefix config prefix. * ${@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) { private void parseConfigKeys(Class<?> configClazz, String prefix) {
for (Field field : findAllField(configClazz)) { for (Field field : findAllField(configClazz)) {

@ -131,6 +131,11 @@ public class SpringValueRegistry implements DisposableBean {
refreshScopeKeys.addAll(keys); 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) { public boolean isRefreshScopeKey(String key) {
if (refreshScopeKeys.contains(key)) { if (refreshScopeKeys.contains(key)) {
return true; return true;

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

Loading…
Cancel
Save