Merge pull request #39948 from christophstrobl

* gh-39948:
  Polish "Delay interaction with Lazy CqlSession bean until first usage"
  Delay interaction with Lazy CqlSession bean until first usage

Closes gh-39948
This commit is contained in:
Andy Wilkinson
2024-04-10 18:16:41 +01:00

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.domain.EntityScanPackages;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;
import org.springframework.data.cassandra.CassandraManagedTypes;
import org.springframework.data.cassandra.SessionFactory;
@@ -54,6 +55,7 @@ import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver;
* @author Eddú Meléndez
* @author Mark Paluch
* @author Madhura Bhave
* @author Christoph Strobl
* @since 1.3.0
*/
@AutoConfiguration(after = CassandraAutoConfiguration.class)
@@ -63,7 +65,7 @@ public class CassandraDataAutoConfiguration {
private final CqlSession session;
public CassandraDataAutoConfiguration(CqlSession session) {
public CassandraDataAutoConfiguration(@Lazy CqlSession session) {
this.session = session;
}
@@ -95,7 +97,7 @@ public class CassandraDataAutoConfiguration {
public CassandraConverter cassandraConverter(CassandraMappingContext mapping,
CassandraCustomConversions conversions) {
MappingCassandraConverter converter = new MappingCassandraConverter(mapping);
converter.setCodecRegistry(this.session.getContext().getCodecRegistry());
converter.setCodecRegistry(() -> this.session.getContext().getCodecRegistry());
converter.setCustomConversions(conversions);
converter.setUserTypeResolver(new SimpleUserTypeResolver(this.session));
return converter;