Skip to content

Commit

Permalink
Merge pull request #39308 from jonasgeiregat
Browse files Browse the repository at this point in the history
* pr/39308:
  Polish "Use generic wildcard for Pulsar beans"
  Use generic wildcard for Pulsar beans

Closes gh-39308
  • Loading branch information
mhalbritter committed Jan 31, 2024
2 parents 231aa01 + cee2491 commit 7842f73
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
* @author Soby Chacko
* @author Alexander Preuß
* @author Phillip Webb
* @author Jonas Geiregat
* @since 3.2.0
*/
@AutoConfiguration
Expand Down Expand Up @@ -131,7 +132,7 @@ PulsarTemplate<?> pulsarTemplate(PulsarProducerFactory<?> pulsarProducerFactory,

@Bean
@ConditionalOnMissingBean(PulsarConsumerFactory.class)
DefaultPulsarConsumerFactory<Object> pulsarConsumerFactory(PulsarClient pulsarClient,
DefaultPulsarConsumerFactory<?> pulsarConsumerFactory(PulsarClient pulsarClient,
ObjectProvider<ConsumerBuilderCustomizer<?>> customizersProvider) {
List<ConsumerBuilderCustomizer<?>> customizers = new ArrayList<>();
customizers.add(this.propertiesMapper::customizeConsumerBuilder);
Expand All @@ -150,7 +151,7 @@ private void applyConsumerBuilderCustomizers(List<ConsumerBuilderCustomizer<?>>

@Bean
@ConditionalOnMissingBean(name = "pulsarListenerContainerFactory")
ConcurrentPulsarListenerContainerFactory<Object> pulsarListenerContainerFactory(
ConcurrentPulsarListenerContainerFactory<?> pulsarListenerContainerFactory(
PulsarConsumerFactory<Object> pulsarConsumerFactory, SchemaResolver schemaResolver,
TopicResolver topicResolver, Environment environment) {
PulsarContainerProperties containerProperties = new PulsarContainerProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.TestConfiguration;
Expand Down Expand Up @@ -373,6 +374,15 @@ <T> void whenHasUserDefinedCustomizersAppliesInCorrectOrder() {
});
}

@Test
void injectsExpectedBeanWithExplicitGenericType() {
this.contextRunner.withBean(ExplicitGenericTypeConfig.class)
.run((context) -> assertThat(context).getBean(ExplicitGenericTypeConfig.class)
.hasFieldOrPropertyWithValue("consumerFactory", context.getBean(PulsarConsumerFactory.class))
.hasFieldOrPropertyWithValue("containerFactory",
context.getBean(ConcurrentPulsarListenerContainerFactory.class)));
}

@TestConfiguration(proxyBeanMethods = false)
static class ConsumerBuilderCustomizersConfig {

Expand All @@ -390,6 +400,20 @@ ConsumerBuilderCustomizer<?> customizerBar() {

}

static class ExplicitGenericTypeConfig {

@Autowired
PulsarConsumerFactory<TestType> consumerFactory;

@Autowired
ConcurrentPulsarListenerContainerFactory<TestType> containerFactory;

static class TestType {

}

}

}

@Nested
Expand Down

0 comments on commit 7842f73

Please sign in to comment.