From 76a1295e3f8ff89b6866c38b87608e11082893c8 Mon Sep 17 00:00:00 2001 From: liaozan <378024053@qq.com> Date: Tue, 2 May 2023 14:50:50 +0800 Subject: [PATCH] Ensure the PropertiesPreparedEventListener can print log correctly --- .../apollo/ConfigurablePropertiesLoader.java | 9 ++++++--- .../apollo/listener/PropertiesPreparedEvent.java | 11 +++++++++-- .../PropertiesPreparedEventListenerAdapter.java | 6 +++++- .../LoggerPropertiesPreparedEventListener.java | 2 -- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ConfigurablePropertiesLoader.java b/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ConfigurablePropertiesLoader.java index 43df32d..1069ae0 100644 --- a/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ConfigurablePropertiesLoader.java +++ b/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/ConfigurablePropertiesLoader.java @@ -35,10 +35,13 @@ class ConfigurablePropertiesLoader { */ private static final String PROPERTIES_PROPERTY_SOURCE = "ConfigurablePropertiesPropertySource"; + private final DeferredLogFactory deferredLogFactory; + private final Log log; - ConfigurablePropertiesLoader(DeferredLogFactory logFactory) { - this.log = logFactory.getLog(ConfigurablePropertiesLoader.class); + ConfigurablePropertiesLoader(DeferredLogFactory deferredLogFactory) { + this.deferredLogFactory = deferredLogFactory; + this.log = deferredLogFactory.getLog(ConfigurablePropertiesLoader.class); } void load(ConfigurableEnvironment environment, SpringApplication application) { @@ -74,7 +77,7 @@ class ConfigurablePropertiesLoader { compositePropertySource.addPropertySource(propertySource); ConfigurableProperties boundProperties = properties.bind(environment); - eventMulticaster.multicastEvent(new PropertiesPreparedEvent(boundProperties, propertySource, environment, application)); + eventMulticaster.multicastEvent(new PropertiesPreparedEvent(environment, deferredLogFactory, propertySource, boundProperties, application)); }); } diff --git a/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/listener/PropertiesPreparedEvent.java b/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/listener/PropertiesPreparedEvent.java index 6a29627..60206e2 100644 --- a/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/listener/PropertiesPreparedEvent.java +++ b/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/listener/PropertiesPreparedEvent.java @@ -4,6 +4,7 @@ import com.schbrain.common.util.properties.SchbrainMapPropertySource; import com.schbrain.common.util.support.ConfigurableProperties; import lombok.Getter; import org.springframework.boot.SpringApplication; +import org.springframework.boot.logging.DeferredLogFactory; import org.springframework.context.ApplicationEvent; import org.springframework.core.env.ConfigurableEnvironment; @@ -18,15 +19,21 @@ public class PropertiesPreparedEvent extends ApplicationEvent { private final ConfigurableEnvironment environment; + private final DeferredLogFactory deferredLogFactory; + private final SchbrainMapPropertySource propertySource; private final SpringApplication application; - public PropertiesPreparedEvent(ConfigurableProperties properties, SchbrainMapPropertySource propertySource, - ConfigurableEnvironment environment, SpringApplication application) { + public PropertiesPreparedEvent(ConfigurableEnvironment environment, + DeferredLogFactory deferredLogFactory, + SchbrainMapPropertySource propertySource, + ConfigurableProperties properties, + SpringApplication application) { super(properties); this.environment = environment; this.propertySource = propertySource; + this.deferredLogFactory = deferredLogFactory; this.application = application; } diff --git a/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/listener/PropertiesPreparedEventListenerAdapter.java b/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/listener/PropertiesPreparedEventListenerAdapter.java index 91cfeb0..a6a364e 100644 --- a/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/listener/PropertiesPreparedEventListenerAdapter.java +++ b/starters/apollo-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/apollo/listener/PropertiesPreparedEventListenerAdapter.java @@ -1,6 +1,7 @@ package com.schbrain.framework.autoconfigure.apollo.listener; import com.schbrain.common.util.support.ConfigurableProperties; +import org.apache.commons.logging.Log; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -14,6 +15,8 @@ public class PropertiesPreparedEventListenerAdapter propertyType; + protected Log log; + public PropertiesPreparedEventListenerAdapter() { ParameterizedType parameterizedType = (ParameterizedType) getClass().getGenericSuperclass(); Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); @@ -23,7 +26,8 @@ public class PropertiesPreparedEventListenerAdapter { @Override -- GitLab