From 6163be2aa74e2a078ec8c758aa61097c86b2f77f Mon Sep 17 00:00:00 2001 From: Ben Hale Date: Fri, 15 May 2020 17:27:58 -0700 Subject: [PATCH] ApplicationEventListeners Previously, the implementations of the EnvironmentPostProcessors added ApplicationEventListener to their interface as well. These implementations tested fine, but of course since there was no full integration test to ensure that they were registered I forgot to add them to spring.factories. This change adds their declarations as ApplicationEventListeners to the spring.factories file and ensures that the logs are replayed when the application is finished preparing. Signed-off-by: Ben Hale --- README.md | 2 +- pom.xml | 4 ++-- .../BindingSpecificEnvironmentPostProcessor.java | 12 ++++++------ src/main/resources/META-INF/spring.factories | 3 +++ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2afa3e7..3da8895 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ if (bindings.size() > 0) { ``` ## Spring Boot Configuration -The more common usage of the library is opt-in automatic Spring Boot configuration. Setting the `org.springframework.cloud.bindings.boot.enabled=true` System Property results in the following: +The more common usage of the library is opt-in automatic Spring Boot configuration. Setting the `org.springframework.cloud.bindings.boot.enable=true` System Property results in the following: * Adds a `PropertySource` with a flattened representation (`cnb.bindings.{name}.{metadata,secret}.*`) of the bindings. * Adds a `PropertySource` with binding-specific Spring Boot configuration properties. diff --git a/pom.xml b/pom.xml index a508d35..9353089 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud bindings - 0.0.1.BUILD-SNAPSHOT + 0.0.1-SNAPSHOT Spring Cloud Cloud Native Buildpacks Bindings Java Library and Auto-configuration for Cloud Native Buildpack Bindings @@ -26,7 +26,7 @@ 1.8 3.0.2 - 2.2.7.RELEASE + 2.3.0.RELEASE 3.8.1 diff --git a/src/main/java/org/springframework/cloud/bindings/boot/BindingSpecificEnvironmentPostProcessor.java b/src/main/java/org/springframework/cloud/bindings/boot/BindingSpecificEnvironmentPostProcessor.java index 8b62b2a..1ebb54e 100644 --- a/src/main/java/org/springframework/cloud/bindings/boot/BindingSpecificEnvironmentPostProcessor.java +++ b/src/main/java/org/springframework/cloud/bindings/boot/BindingSpecificEnvironmentPostProcessor.java @@ -53,9 +53,9 @@ public final class BindingSpecificEnvironmentPostProcessor implements Applicatio */ public static final String BINDING_SPECIFIC_PROPERTY_SOURCE_NAME = "cnbBindingSpecific"; - final List processors; + private static final DeferredLog LOG = new DeferredLog(); - private final DeferredLog log = new DeferredLog(); + final List processors; private final Bindings bindings; @@ -82,7 +82,7 @@ public final class BindingSpecificEnvironmentPostProcessor implements Applicatio @Override public void onApplicationEvent(ApplicationPreparedEvent event) { - this.log.switchTo(getClass()); + LOG.switchTo(getClass()); } @Override @@ -92,18 +92,18 @@ public final class BindingSpecificEnvironmentPostProcessor implements Applicatio } if (bindings.getBindings().isEmpty()) { - log.debug("No CNB Bindings found. Skipping Environment post-processing."); + LOG.debug("No CNB Bindings found. Skipping Environment post-processing."); return; } Map properties = new HashMap<>(); processors.forEach(processor -> processor.process(environment, bindings, properties)); if (properties.isEmpty()) { - log.debug("No properties set from CNB Bindings. Skipping PropertySource creation."); + LOG.debug("No properties set from CNB Bindings. Skipping PropertySource creation."); return; } - log.info("Creating binding-specific PropertySource from CNB Bindings"); + LOG.info("Creating binding-specific PropertySource from CNB Bindings"); contributePropertySource(BINDING_SPECIFIC_PROPERTY_SOURCE_NAME, properties, environment); } diff --git a/src/main/resources/META-INF/spring.factories b/src/main/resources/META-INF/spring.factories index 336c563..2d0eaa8 100644 --- a/src/main/resources/META-INF/spring.factories +++ b/src/main/resources/META-INF/spring.factories @@ -1,3 +1,6 @@ +org.springframework.context.ApplicationListener=\ + org.springframework.cloud.bindings.boot.BindingFlattenedEnvironmentPostProcessor, \ + org.springframework.cloud.bindings.boot.BindingSpecificEnvironmentPostProcessor org.springframework.boot.env.EnvironmentPostProcessor=\ org.springframework.cloud.bindings.boot.BindingFlattenedEnvironmentPostProcessor, \ org.springframework.cloud.bindings.boot.BindingSpecificEnvironmentPostProcessor