Addressing snake_case properties binding

Related to #1495
This commit is contained in:
Soby Chacko
2018-10-08 18:17:16 -04:00
parent 0249867e63
commit 60b6f02a49
3 changed files with 13 additions and 4 deletions

View File

@@ -284,8 +284,9 @@ public class BindingService implements ApplicationContextAware {
}
};
//Re-bind extended properties to check which properties are really provided by the application
extendedPropertiesResolverBinder.bind(producer ? bindingPropertyPrefixOnBinder + ".producer" : bindingPropertyPrefixOnBinder + ".consumer",
Bindable.ofInstance(extendedProperties), handler);
String configElements = producer ? bindingPropertyPrefixOnBinder + ".producer" : bindingPropertyPrefixOnBinder + ".consumer";
String uniformConfigElements = StringUtils.replace(configElements, "_", "").toLowerCase();
extendedPropertiesResolverBinder.bind(uniformConfigElements, Bindable.ofInstance(extendedProperties), handler);
BinderSpecificPropertiesProvider defaultProperties = BeanUtils.instantiateClass(extendedPropertiesEntryClass);
extendedPropertiesResolverBinder.bind(defaultsPrefix, Bindable.ofInstance(defaultProperties));

View File

@@ -33,6 +33,7 @@ import org.springframework.boot.context.properties.source.ConfigurationPropertyS
import org.springframework.core.convert.ConversionService;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* A {@link Map} implementation that initializes its entries by binding values from the
@@ -114,7 +115,8 @@ public class EnvironmentEntryInitializingTreeMap<T> extends AbstractMap<String,
};
String configElements = "spring.cloud.stream.bindings." + key;
binder.bind(configElements.toLowerCase(), Bindable.ofInstance(defaultProperties), handler);
String uniformConfigElements = StringUtils.replace(configElements, "_", "").toLowerCase();
binder.bind(uniformConfigElements, Bindable.ofInstance(defaultProperties), handler);
((MergableProperties)defaultProperties).merge((MergableProperties) value, setProperties.toArray(new String[0]));
return this.delegate.put(key, value);

View File

@@ -448,7 +448,9 @@ public class BindingServiceTests {
"--spring.cloud.stream.default.producer.partitionCount=10",
"--spring.cloud.stream.bindings.output2.producer.partitionCount=1",
"--spring.cloud.stream.bindings.inputXyz.contentType=application/json",
"--spring.cloud.stream.bindings.inputFooBar.contentType=application/avro");
"--spring.cloud.stream.bindings.inputFooBar.contentType=application/avro",
"--spring.cloud.stream.bindings.input_snake_case.contentType=application/avro"
);
BindingServiceProperties bindingServiceProperties = run.getBeanFactory().getBean(BindingServiceProperties.class);
Map<String, BindingProperties> bindings = bindingServiceProperties.getBindings();
@@ -467,6 +469,7 @@ public class BindingServiceTests {
assertThat(bindings.get("inputXyz").getContentType()).isEqualTo("application/json");
assertThat(bindings.get("inputFooBar").getContentType()).isEqualTo("application/avro");
assertThat(bindings.get("inputFooBarBuzz").getContentType()).isEqualTo("text/plain");
assertThat(bindings.get("input_snake_case").getContentType()).isEqualTo("application/avro");
}
@EnableBinding(FooBinding.class)
@@ -500,6 +503,9 @@ public class BindingServiceTests {
@Input("inputFooBarBuzz")
SubscribableChannel inFooBarBuzz();
@Input("input_snake_case")
SubscribableChannel inWithSnakeCase();
}
@Test