Skip to content

Commit 8343942

Browse files
christophstroblwilkinsona
authored andcommitted
Delay interaction with Lazy CqlSession bean until first usage
Though the CqlSession provided by the CassandraAutoConfiguration can be lazy, the configuration for Data Cassandra triggers early bean instantiation. This commit uses new APIs in Data Cassandra to make use of the intended lazy bean initialization and therefore prevents the application from failing to start up when Cassandra might not yet be ready. See gh-39948
1 parent 3ac7ead commit 8343942

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.boot.autoconfigure.domain.EntityScanPackages;
3333
import org.springframework.boot.context.properties.bind.Binder;
3434
import org.springframework.context.annotation.Bean;
35+
import org.springframework.context.annotation.Lazy;
3536
import org.springframework.core.env.Environment;
3637
import org.springframework.data.cassandra.CassandraManagedTypes;
3738
import org.springframework.data.cassandra.SessionFactory;
@@ -54,6 +55,7 @@
5455
* @author Eddú Meléndez
5556
* @author Mark Paluch
5657
* @author Madhura Bhave
58+
* @author Christoph Strobl
5759
* @since 1.3.0
5860
*/
5961
@AutoConfiguration(after = CassandraAutoConfiguration.class)
@@ -63,7 +65,7 @@ public class CassandraDataAutoConfiguration {
6365

6466
private final CqlSession session;
6567

66-
public CassandraDataAutoConfiguration(CqlSession session) {
68+
public CassandraDataAutoConfiguration(@Lazy CqlSession session) {
6769
this.session = session;
6870
}
6971

@@ -95,7 +97,7 @@ public CassandraMappingContext cassandraMappingContext(CassandraManagedTypes cas
9597
public CassandraConverter cassandraConverter(CassandraMappingContext mapping,
9698
CassandraCustomConversions conversions) {
9799
MappingCassandraConverter converter = new MappingCassandraConverter(mapping);
98-
converter.setCodecRegistry(this.session.getContext().getCodecRegistry());
100+
converter.setCodecRegistry(() -> this.session.getContext().getCodecRegistry());
99101
converter.setCustomConversions(conversions);
100102
converter.setUserTypeResolver(new SimpleUserTypeResolver(this.session));
101103
return converter;

0 commit comments

Comments
 (0)