GH-75: add EnvPP for CS-AWS exclusion

Fixes https://github.com/spring-cloud/stream-applications/issues/75
This commit is contained in:
Timo Salm
2020-07-08 17:33:13 +02:00
committed by GitHub
parent c21533e42c
commit c397df191b
4 changed files with 95 additions and 1 deletions

View File

@@ -0,0 +1,45 @@
/*
* Copyright 2020-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.fn.common.aws.s3;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.cloud.aws.autoconfigure.context.ContextResourceLoaderAutoConfiguration;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.StandardEnvironment;
/**
* @author Timo Salm
*/
@Order
public class AutoConfigurationExclusionEnvironmentPostProcessor implements EnvironmentPostProcessor {
static final String SPRING_AUTOCONFIGURE_EXCLUDE_PROPERTY = "spring.autoconfigure.exclude";
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
final PropertySource<?> propertySource = environment.getPropertySources()
.get(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
if (propertySource instanceof MapPropertySource) {
((MapPropertySource) propertySource).getSource().put(SPRING_AUTOCONFIGURE_EXCLUDE_PROPERTY,
ContextResourceLoaderAutoConfiguration.class.getCanonicalName());
}
}
}

View File

@@ -1,3 +1,5 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.fn.common.aws.s3.CompatibleStorageAmazonS3Configuration,\
org.springframework.cloud.fn.common.aws.s3.AmazonS3Configuration
org.springframework.boot.env.EnvironmentPostProcessor=\
org.springframework.cloud.fn.common.aws.s3.AutoConfigurationExclusionEnvironmentPostProcessor

View File

@@ -1 +0,0 @@
spring.autoconfigure.exclude=org.springframework.cloud.aws.autoconfigure.context.ContextResourceLoaderAutoConfiguration

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2020-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.fn.common.aws.s3;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import static org.springframework.cloud.fn.common.aws.s3.AutoConfigurationExclusionEnvironmentPostProcessor
.SPRING_AUTOCONFIGURE_EXCLUDE_PROPERTY;
/**
* @author Timo Salm
*/
class AutoConfigurationExclusionEnvironmentPostProcessorTests {
@Test
public void addsConfigurationPropertyToExcludeAmazonS3AutoConfiguration() {
final ConfigurableApplicationContext context = new SpringApplicationBuilder()
.sources(AutoConfigurationExclusionEnvironmentPostProcessor.class)
.web(WebApplicationType.NONE)
.build()
.run();
final ConfigurableEnvironment environment = context.getEnvironment();
Assertions.assertEquals(
"org.springframework.cloud.aws.autoconfigure.context.ContextResourceLoaderAutoConfiguration",
environment.getProperty(SPRING_AUTOCONFIGURE_EXCLUDE_PROPERTY));
}
}