Skip to content

Commit e8661f6

Browse files
nosansnicoll
authored andcommitted
Auto-configure CqlTemplate and ReactiveCqlTemplate
See gh-44291 Signed-off-by: Dmytro Nosan <dimanosan@gmail.com>
1 parent e884aa3 commit e8661f6

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,6 +45,8 @@
4545
import org.springframework.data.cassandra.core.convert.CassandraConverter;
4646
import org.springframework.data.cassandra.core.convert.CassandraCustomConversions;
4747
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
48+
import org.springframework.data.cassandra.core.cql.CqlOperations;
49+
import org.springframework.data.cassandra.core.cql.CqlTemplate;
4850
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
4951
import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver;
5052

@@ -120,6 +122,12 @@ public CassandraTemplate cassandraTemplate(SessionFactory sessionFactory, Cassan
120122
return new CassandraTemplate(sessionFactory, converter);
121123
}
122124

125+
@Bean
126+
@ConditionalOnMissingBean(CqlOperations.class)
127+
public CqlTemplate cqlTemplate(SessionFactory sessionFactory) {
128+
return new CqlTemplate(sessionFactory);
129+
}
130+
123131
@Bean
124132
@ConditionalOnMissingBean
125133
public CassandraCustomConversions cassandraCustomConversions() {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfiguration.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,6 +30,8 @@
3030
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
3131
import org.springframework.data.cassandra.core.ReactiveCassandraTemplate;
3232
import org.springframework.data.cassandra.core.convert.CassandraConverter;
33+
import org.springframework.data.cassandra.core.cql.ReactiveCqlOperations;
34+
import org.springframework.data.cassandra.core.cql.ReactiveCqlTemplate;
3335
import org.springframework.data.cassandra.core.cql.session.DefaultBridgedReactiveSession;
3436
import org.springframework.data.cassandra.core.cql.session.DefaultReactiveSessionFactory;
3537

@@ -65,4 +67,10 @@ public ReactiveCassandraTemplate reactiveCassandraTemplate(ReactiveSession react
6567
return new ReactiveCassandraTemplate(reactiveCassandraSession, converter);
6668
}
6769

70+
@Bean
71+
@ConditionalOnMissingBean(ReactiveCqlOperations.class)
72+
public ReactiveCqlTemplate reactiveCqlTemplate(ReactiveSessionFactory reactiveCassandraSessionFactory) {
73+
return new ReactiveCqlTemplate(reactiveCassandraSessionFactory);
74+
}
75+
6876
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@
3333
import org.springframework.data.cassandra.core.CassandraTemplate;
3434
import org.springframework.data.cassandra.core.convert.CassandraConverter;
3535
import org.springframework.data.cassandra.core.convert.CassandraCustomConversions;
36+
import org.springframework.data.cassandra.core.cql.CqlTemplate;
3637
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
3738
import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver;
3839
import org.springframework.data.domain.ManagedTypes;
@@ -65,6 +66,12 @@ void templateExists() {
6566
assertThat(this.context.getBeanNamesForType(CassandraTemplate.class)).hasSize(1);
6667
}
6768

69+
@Test
70+
void cqlTemplateExists() {
71+
load(CassandraMockConfiguration.class);
72+
assertThat(this.context.getBeanNamesForType(CqlTemplate.class)).hasSize(1);
73+
}
74+
6875
@Test
6976
void entityScanShouldSetManagedTypes() {
7077
load(EntityScanConfig.class);

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfigurationTests.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@
2727
import org.springframework.context.annotation.Configuration;
2828
import org.springframework.data.cassandra.core.ReactiveCassandraTemplate;
2929
import org.springframework.data.cassandra.core.convert.CassandraConverter;
30+
import org.springframework.data.cassandra.core.cql.ReactiveCqlTemplate;
3031
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
3132
import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver;
3233
import org.springframework.data.domain.ManagedTypes;
@@ -58,6 +59,12 @@ void templateExists() {
5859
assertThat(this.context.getBeanNamesForType(ReactiveCassandraTemplate.class)).hasSize(1);
5960
}
6061

62+
@Test
63+
void reactiveCqlTemplateExists() {
64+
load("spring.cassandra.keyspaceName:boot_test");
65+
assertThat(this.context.getBeanNamesForType(ReactiveCqlTemplate.class)).hasSize(1);
66+
}
67+
6168
@Test
6269
void entityScanShouldSetManagedTypes() {
6370
load(EntityScanConfig.class, "spring.cassandra.keyspaceName:boot_test");

0 commit comments

Comments
 (0)