Exclude test support binder from binder type registry
- Given the TestSupportBinder has its own BinderFactory that returns the TestSupportBinder, we need to exclude the BinderType entry of TestSupportBinder detected from classpath - This will make sure to exclude test support binder when TestSupportBinderAutoConfiguration is excluded when using other explicit binder in tests Resolves #827 Set defaultCandidate to false for TestSupportBinder - Set `defaultCandidate` to false for the TestSupportBinder using an environment post processor - At BinderFactoryConfiguration, don't override the 'BinderProperties' set via declared binders - Set `defaultCandidate` to `true` only for the binders set via BinderTypeRegistry without overriding their binder properties
This commit is contained in:
committed by
Marius Bogoevici
parent
8e87f2bece
commit
69cbc7f05b
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2017 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
|
||||
*
|
||||
* http://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.stream.test.binder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
|
||||
/**
|
||||
* An {@link EnvironmentPostProcessor} that sets some configuration properties for {@link TestSupportBinder}.
|
||||
*
|
||||
* @author Ilayaperumal Gopinathan
|
||||
*/
|
||||
public class TestBinderEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
Map<String, Object> propertiesToAdd = new HashMap<>();
|
||||
propertiesToAdd.put("spring.cloud.stream.binders.test.defaultCandidate", "false");
|
||||
environment.getPropertySources().addLast(new MapPropertySource("testBinderConfig", propertiesToAdd));
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,4 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration:\
|
||||
org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration
|
||||
org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=\
|
||||
org.springframework.cloud.stream.test.binder.TestBinderEnvironmentPostProcessor
|
||||
|
||||
Reference in New Issue
Block a user