Skip to content

Commit 602cabc

Browse files
committed
Deactivation Kafka auto-configuration
1 parent 5e9623e commit 602cabc

File tree

2 files changed

+24
-29
lines changed

2 files changed

+24
-29
lines changed

generators/spring-boot/templates/src/test/resources/config/application.yml.ejs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ mongock:
6363
spring:
6464
application:
6565
name: <%= baseName %>
66-
<%_ if (applicationTypeGateway) { _%>
66+
<%_ if (applicationTypeGateway || messageBrokerKafka) { _%>
6767
autoconfigure:
6868
exclude:
69+
<%_ if (applicationTypeGateway) { _%>
6970
- org.springframework.cloud.gateway.config.GatewayMetricsAutoConfiguration
71+
<%_ } _%>
72+
<%_ if (messageBrokerKafka) { _%>
73+
- org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration
74+
<%_ } _%>
7075
<%_ } _%>
7176
<%_ if (serviceDiscoveryEureka || serviceDiscoveryConsul || messageBrokerAny) { _%>
7277
cloud:
@@ -86,24 +91,11 @@ spring:
8691
<%_ } _%>
8792
<%_ if (messageBrokerKafka) { _%>
8893
function:
89-
definition: kafkaConsumer;kafkaProducer
94+
scan:
95+
enabled: false
96+
definition: ''
9097
stream:
91-
enabled: false
92-
kafka:
93-
binder:
94-
replicationFactor: 1
95-
auto-create-topics: true
96-
bindings:
97-
binding-out-0:
98-
content-type: text/plain
99-
group: <%= dasherizedBaseName %>
100-
kafkaConsumer-in-0:
101-
destination: sse-topic
102-
content-type: text/plain
103-
group: <%= dasherizedBaseName %>
104-
kafkaProducer-out-0:
105-
content-type: text/plain
106-
group: <%= dasherizedBaseName %>
98+
defaultBinder: test
10799
<%_ } _%>
108100
<%_ if (messageBrokerPulsar) { _%>
109101
function:
@@ -230,3 +222,7 @@ management:
230222
health:
231223
mail:
232224
enabled: false
225+
<%_ if (messageBrokerKafka) { _%>
226+
kafka:
227+
enabled: false
228+
<%_ } _%>

generators/spring-cloud/generators/kafka/templates/src/test/java/_package_/config/KafkaTestContainersSpringContextCustomizerFactory.java.ejs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,33 @@ public class KafkaTestContainersSpringContextCustomizerFactory implements Contex
3434

3535
private Logger log = LoggerFactory.getLogger(KafkaTestContainersSpringContextCustomizerFactory.class);
3636

37-
private static KafkaTestContainer kafkaBean;
38-
3937
@Override
4038
public ContextCustomizer createContextCustomizer(Class<?> testClass, List<ContextConfigurationAttributes> configAttributes) {
4139

4240
return new ContextCustomizer() {
4341
@Override
4442
public void customizeContext(ConfigurableApplicationContext context,
4543
MergedContextConfiguration mergedConfig) {
46-
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
4744
TestPropertyValues testValues = TestPropertyValues.empty();
4845
EmbeddedKafka kafkaAnnotation = AnnotatedElementUtils.findMergedAnnotation(testClass, EmbeddedKafka.class);
4946
if (null != kafkaAnnotation) {
5047
log.debug("detected the EmbeddedKafka annotation on class {}", testClass.getName());
51-
log.info("Warming up the kafka broker");
52-
if (null == kafkaBean) {
53-
kafkaBean = beanFactory.createBean(KafkaTestContainer.class);
54-
beanFactory.registerSingleton(KafkaTestContainer.class.getName(), kafkaBean);
55-
}
56-
testValues = testValues.and("spring.cloud.stream.kafka.binder.brokers=" + kafkaBean.getKafkaContainer().getHost() + ':' + kafkaBean.getKafkaContainer().getFirstMappedPort());
57-
testValues = testValues.and("spring.cloud.stream.enabled=true");
48+
testValues = testValues.and("spring.cloud.function.scan.enabled=true");
49+
testValues = testValues.and("spring.cloud.function.definition=kafkaConsumer;kafkaProducer");
50+
testValues = testValues.and("spring.cloud.stream.bindings.binding-out-0.content-type=text/plain");
51+
testValues = testValues.and("spring.cloud.stream.bindings.binding-out-0.group=<%= dasherizedBaseName %>");
52+
testValues = testValues.and("spring.cloud.stream.bindings.kafkaConsumer-in-0.destination=sse-topic");
53+
testValues = testValues.and("spring.cloud.stream.bindings.kafkaConsumer-in-0.content-type=text/plain");
54+
testValues = testValues.and("spring.cloud.stream.bindings.kafkaConsumer-in-0.group=<%= dasherizedBaseName %>");
55+
testValues = testValues.and("spring.cloud.stream.bindings.kafkaProducer-out-0.content-type=text/plain");
56+
testValues = testValues.and("spring.cloud.stream.bindings.kafkaProducer-out-0.group=<%= dasherizedBaseName %>");
5857
}
5958
testValues.applyTo(context);
6059
}
6160

6261
@Override
6362
public int hashCode() {
64-
return KafkaTestContainer.class.getName().hashCode();
63+
return KafkaTestContainersSpringContextCustomizerFactory.class.getName().hashCode();
6564
}
6665

6766
@Override

0 commit comments

Comments
 (0)