Conditional loading of AVRO message converter

Introducing a property to disable loading the AVRO message converter.
When spring.cloud.stream.avro.enabled is set to false, the converter
is not loaded. By default, it is enabled.

Resolves https://github.com/spring-cloud/spring-cloud-function/issues/854
This commit is contained in:
Soby Chacko
2022-09-21 17:15:06 -04:00
parent 715033c269
commit 87f6013e22
2 changed files with 9 additions and 0 deletions

View File

@@ -166,6 +166,7 @@ public class ContextFunctionCatalogAutoConfiguration {
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(name = "org.apache.avro.Schema")
@ConditionalOnProperty(value = "spring.cloud.stream.avro.enabled", havingValue = "true", matchIfMissing = true)
static class AvroSchemaMessageConverterConfiguration {
@Bean

View File

@@ -37,6 +37,7 @@ import static org.mockito.Mockito.mock;
* Tests the conditional loading aspects of the {@link ContextFunctionCatalogAutoConfiguration}.
*
* @author Chris Bono
* @author Soby Chacko
*/
public class ContextFunctionCatalogAutoConfigurationConditionalLoadingTests {
@@ -58,6 +59,13 @@ public class ContextFunctionCatalogAutoConfigurationConditionalLoadingTests {
.hasSingleBean(AvroSchemaMessageConverter.class));
}
@Test
void avroSchemaMessageConverterBeansNotLoadedWhenAvroOnClasspathButDisabledThroughProperty() {
contextRunner.withPropertyValues("spring.cloud.stream.avro.enabled:false")
.run((context) -> assertThat(context).doesNotHaveBean(AvroSchemaServiceManager.class)
.doesNotHaveBean(AvroSchemaMessageConverter.class));
}
@Test
void avroSchemaMessageConverterBeansNotLoadedWhenAvroNotOnClasspath() {
contextRunner.withClassLoader(new FilteredClassLoader(Schema.class)).run((context) ->