@ -18,12 +18,16 @@
package com.tencent.cloud.polaris.config.listener ;
package com.tencent.cloud.polaris.config.listener ;
import static com.tencent.cloud.polaris.config.condition.ReflectRefreshTypeCondition.POLARIS_CONFIG_REFRESH_TYPE ;
import java.util.Collections ;
import java.util.Collections ;
import com.tencent.cloud.polaris.config.adapter.PolarisConfigRefreshScopeAnnotationDetector ;
import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager ;
import com.tencent.cloud.polaris.config.adapter.PolarisRefreshEntireContextRefresher ;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties ;
import com.tencent.cloud.polaris.config.enums.RefreshType ;
import org.slf4j.Logger ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.slf4j.LoggerFactory ;
import org.springframework.beans.factory.config.ConstructorArgumentValues ;
import org.springframework.beans.factory.config.ConstructorArgumentValues ;
import org.springframework.beans.factory.support.AbstractBeanDefinition ;
import org.springframework.beans.factory.support.AbstractBeanDefinition ;
import org.springframework.beans.factory.support.BeanDefinitionBuilder ;
import org.springframework.beans.factory.support.BeanDefinitionBuilder ;
@ -36,11 +40,7 @@ import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources ;
import org.springframework.core.env.MutablePropertySources ;
import org.springframework.lang.NonNull ;
import org.springframework.lang.NonNull ;
import com.tencent.cloud.polaris.config.adapter.PolarisConfigRefreshScopeAnnotationDetector ;
import static com.tencent.cloud.polaris.config.condition.ReflectRefreshTypeCondition.POLARIS_CONFIG_REFRESH_TYPE ;
import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager ;
import com.tencent.cloud.polaris.config.adapter.PolarisRefreshEntireContextRefresher ;
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties ;
import com.tencent.cloud.polaris.config.enums.RefreshType ;
/ * *
/ * *
* When { @link com . tencent . cloud . polaris . config . adapter . PolarisConfigRefreshScopeAnnotationDetector } detects that
* When { @link com . tencent . cloud . polaris . config . adapter . PolarisConfigRefreshScopeAnnotationDetector } detects that
@ -72,18 +72,15 @@ public class PolarisConfigRefreshOptimizationListener implements ApplicationList
. getBean ( PolarisConfigRefreshScopeAnnotationDetector . class ) ;
. getBean ( PolarisConfigRefreshScopeAnnotationDetector . class ) ;
boolean isRefreshScopeAnnotationUsed = detector . isRefreshScopeAnnotationUsed ( ) ;
boolean isRefreshScopeAnnotationUsed = detector . isRefreshScopeAnnotationUsed ( ) ;
String annotatedRefreshScopeBeanName = detector . getAnnotatedRefreshScopeBeanName ( ) ;
String annotatedRefreshScopeBeanName = detector . getAnnotatedRefreshScopeBeanName ( ) ;
// using System.setProperty to set spring.cloud.polaris.config.refresh-type
// using System.setProperty to set spring.cloud.polaris.config.refresh-type
String value = System . getProperty ( "spring.cloud.polaris.config.refresh-type" ) ;
String value = System . getProperty ( "spring.cloud.polaris.config.refresh-type" ) ;
boolean isSystemSetRefreshType = RefreshType . REFRESH_CONTEXT . toString ( ) . equalsIgnoreCase ( value ) ;
boolean isSystemSetRefreshType = RefreshType . REFRESH_CONTEXT . toString ( ) . equalsIgnoreCase ( value ) ;
// a bean is using @RefreshScope, but the config refresh type is still [reflect], switch automatically
// a bean is using @RefreshScope, but the config refresh type is still [reflect], switch automatically
if ( isRefreshScopeAnnotationUsed | | isSystemSetRefreshType ) {
if ( isRefreshScopeAnnotationUsed | | isSystemSetRefreshType ) {
if ( isRefreshScopeAnnotationUsed ) {
if ( isRefreshScopeAnnotationUsed ) {
LOGGER . warn ( "Detected that the bean [{}] is using @RefreshScope annotation, but the config refresh type is still [reflect]. "
LOGGER . warn ( "Detected that the bean [{}] is using @RefreshScope annotation, but the config refresh type is still [reflect]. "
+ "[SCT] will automatically switch to [refresh_context]." , annotatedRefreshScopeBeanName ) ;
+ "[SCT] will automatically switch to [refresh_context]." , annotatedRefreshScopeBeanName ) ;
}
}
if ( isSystemSetRefreshType ) {
if ( isSystemSetRefreshType ) {
LOGGER . warn ( "Detected that using System.setProperty to set spring.cloud.polaris.config.refresh-type = refresh_context, but the config refresh type is still [reflect]. "
LOGGER . warn ( "Detected that using System.setProperty to set spring.cloud.polaris.config.refresh-type = refresh_context, but the config refresh type is still [reflect]. "
+ "[SCT] will automatically switch to [refresh_context]." ) ;
+ "[SCT] will automatically switch to [refresh_context]." ) ;