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 <bhale@vmware.com>
This commit is contained in:
Ben Hale
2020-05-15 17:27:58 -07:00
parent ade8797e09
commit 6163be2aa7
4 changed files with 12 additions and 9 deletions

View File

@@ -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.

View File

@@ -6,7 +6,7 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>bindings</artifactId>
<version>0.0.1.BUILD-SNAPSHOT</version>
<version>0.0.1-SNAPSHOT</version>
<name>Spring Cloud Cloud Native Buildpacks Bindings</name>
<description>Java Library and Auto-configuration for Cloud Native Buildpack Bindings</description>
@@ -26,7 +26,7 @@
<properties>
<java.version>1.8</java.version>
<jsr305.version>3.0.2</jsr305.version>
<spring-boot.version>2.2.7.RELEASE</spring-boot.version>
<spring-boot.version>2.3.0.RELEASE</spring-boot.version>
<!-- Plugins -->
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>

View File

@@ -53,9 +53,9 @@ public final class BindingSpecificEnvironmentPostProcessor implements Applicatio
*/
public static final String BINDING_SPECIFIC_PROPERTY_SOURCE_NAME = "cnbBindingSpecific";
final List<BindingsPropertiesProcessor> processors;
private static final DeferredLog LOG = new DeferredLog();
private final DeferredLog log = new DeferredLog();
final List<BindingsPropertiesProcessor> 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<String, Object> 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);
}

View File

@@ -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