1919import java .time .Duration ;
2020
2121import jakarta .annotation .PostConstruct ;
22- import org .apache .commons .logging .Log ;
23- import org .apache .commons .logging .LogFactory ;
2422
2523import org .springframework .cloud .bootstrap .config .PropertySourceLocator ;
2624import org .springframework .core .env .AbstractEnvironment ;
2725import org .springframework .core .env .MapPropertySource ;
26+ import org .springframework .core .log .LogAccessor ;
2827import org .springframework .scheduling .TaskScheduler ;
2928import org .springframework .scheduling .support .PeriodicTrigger ;
3029
3837 */
3938public class PollingConfigMapChangeDetector extends ConfigurationChangeDetector {
4039
41- protected Log log = LogFactory . getLog ( getClass () );
40+ private static final LogAccessor LOG = new LogAccessor ( PollingConfigMapChangeDetector . class );
4241
4342 private final PropertySourceLocator propertySourceLocator ;
4443
@@ -48,6 +47,8 @@ public class PollingConfigMapChangeDetector extends ConfigurationChangeDetector
4847
4948 private final long period ;
5049
50+ // this beans has already a Conditional on this property, we only have it here
51+ // in case it is created manually.
5152 private final boolean monitorConfigMaps ;
5253
5354 public PollingConfigMapChangeDetector (AbstractEnvironment environment , ConfigReloadProperties properties ,
@@ -63,19 +64,22 @@ public PollingConfigMapChangeDetector(AbstractEnvironment environment, ConfigRel
6364
6465 @ PostConstruct
6566 private void init () {
66- log .info ("Kubernetes polling configMap change detector activated" );
67- PeriodicTrigger trigger = new PeriodicTrigger (Duration .ofMillis (period ));
68- trigger .setInitialDelay (Duration .ofMillis (period ));
69- taskExecutor .schedule (this ::executeCycle , trigger );
67+ if (monitorConfigMaps ) {
68+ LOG .info (() -> "Kubernetes polling configMap change detector activated" );
69+ PeriodicTrigger trigger = new PeriodicTrigger (Duration .ofMillis (period ));
70+ trigger .setInitialDelay (Duration .ofMillis (period ));
71+ taskExecutor .schedule (this ::executeCycle , trigger );
72+ }
73+ else {
74+ LOG .debug (() -> "Kubernetes polling configMap change detector disabled" );
75+ }
7076 }
7177
7278 private void executeCycle () {
73- if (monitorConfigMaps ) {
74- boolean changedConfigMap = ConfigReloadUtil .reload (propertySourceLocator , environment , propertySourceClass );
75- if (changedConfigMap ) {
76- log .info ("Detected change in config maps" );
77- reloadProperties ();
78- }
79+ boolean changedConfigMap = ConfigReloadUtil .reload (propertySourceLocator , environment , propertySourceClass );
80+ if (changedConfigMap ) {
81+ LOG .info (() -> "Detected change in config maps" );
82+ reloadProperties ();
7983 }
8084 }
8185
0 commit comments