Re-instate search=CURRENT for config properties

In order to run a module as a child context (namespaceing the channels)
you need to have a separate ChannelBindingProperties per context,
so the condition has to have search=CURRENT. For an XD module this
was a problem because the ModuleProperties (a subclass) is needed and that
has to be added in bootstrap (i.e. in the parent context). Fixed by
registering the ModuleProperties as a singleton in the child context.
This commit is contained in:
Dave Syer
2015-07-10 08:44:58 +01:00
parent 99db6d5177
commit 0ba24af395
5 changed files with 44 additions and 16 deletions

View File

@@ -25,7 +25,6 @@ import java.util.Set;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.target.LazyInitTargetSource;
import org.springframework.beans.factory.BeanFactoryUtils;
@@ -57,7 +56,6 @@ import org.springframework.xd.dirt.integration.bus.serializer.kryo.PojoCodec;
* @author David Turanski
*/
@Configuration
public class ChannelBindingAdapterConfiguration {
@Autowired
@@ -172,24 +170,14 @@ public class ChannelBindingAdapterConfiguration {
}
@Configuration
//TODO: make sure to set the SearchStrategy to CURRENT once the module options initializer code is removed.
@ConditionalOnMissingBean(value=ChannelBindingProperties.class)
protected static class ModulePropertiesConfiguration {
@Bean(name = "spring.cloud.channels.CONFIGURATION_PROPERTIES")
public ChannelBindingProperties moduleProperties() {
return new ChannelBindingProperties();
}
}
protected static class CodecConfiguration {
@Autowired
ApplicationContext applicationContext;
@Bean
@ConditionalOnMissingBean(name = "codec")
public MultiTypeCodec codec() {
Map<String, KryoRegistrar> kryoRegistrarMap = applicationContext.getBeansOfType(KryoRegistrar
public MultiTypeCodec<?> codec() {
Map<String, KryoRegistrar> kryoRegistrarMap = this.applicationContext.getBeansOfType(KryoRegistrar
.class);
return new PojoCodec(new ArrayList<>(kryoRegistrarMap.values()));
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2015 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.streams.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author Dave Syer
*
*/
@Configuration
@ConditionalOnMissingBean(value = ChannelBindingProperties.class, search = SearchStrategy.CURRENT)
public class ChannelBindingPropertiesAutoConfiguration {
@Bean(name = "spring.cloud.channels.CONFIGURATION_PROPERTIES")
public ChannelBindingProperties moduleProperties() {
return new ChannelBindingProperties();
}
}

View File

@@ -1 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration:\
org.springframework.cloud.streams.config.ChannelBindingPropertiesAutoConfiguration

View File

@@ -139,7 +139,7 @@ public class ChannelBindingAdapterConfigurationTests {
}
@Configuration
@Import(ChannelBindingAdapterConfiguration.class)
@Import({ChannelBindingAdapterConfiguration.class, ChannelBindingPropertiesAutoConfiguration.class})
protected static class Empty {
@Bean
public LocalMessageBus messageBus() {

View File

@@ -79,6 +79,8 @@ ApplicationContextInitializer<ConfigurableApplicationContext> {
}
}
insert(environment, new MapPropertySource("moduleDefaults", map));
applicationContext.getBeanFactory().registerSingleton(
"spring.cloud.channels.CONFIGURATION_PROPERTIES", this.module);
}
private ModuleDefinition getModuleDefinition(
@@ -131,7 +133,7 @@ ApplicationContextInitializer<ConfigurableApplicationContext> {
}
@Configuration
@ConditionalOnMissingBean(value=ModuleProperties.class, search=SearchStrategy.CURRENT)
@ConditionalOnMissingBean(value = ModuleProperties.class, search = SearchStrategy.CURRENT)
protected static class ModulePropertiesConfiguration {
@Bean(name = "spring.cloud.channels.CONFIGURATION_PROPERTIES")
public ModuleProperties moduleProperties() {