Commit 0516520b authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Fix scope of CqlSessionBuilder bean"

See gh-19899
parent c8105413
...@@ -45,13 +45,13 @@ class CassandraAutoConfigurationTests { ...@@ -45,13 +45,13 @@ class CassandraAutoConfigurationTests {
.withConfiguration(AutoConfigurations.of(CassandraAutoConfiguration.class)); .withConfiguration(AutoConfigurations.of(CassandraAutoConfiguration.class));
@Test @Test
void cqlSessionBuilderThreadSafe() { void cqlSessionBuildHasScopePrototype() {
this.contextRunner.run((context) -> { this.contextRunner.run((context) -> {
CqlIdentifier keyspace = CqlIdentifier.fromCql("test"); CqlIdentifier keyspace = CqlIdentifier.fromCql("test");
assertThat(context).hasSingleBean(CqlSessionBuilder.class); CqlSessionBuilder firstBuilder = context.getBean(CqlSessionBuilder.class);
assertThat(context.getBean(CqlSessionBuilder.class).withKeyspace(keyspace)) assertThat(firstBuilder.withKeyspace(keyspace)).hasFieldOrPropertyWithValue("keyspace", keyspace);
.hasFieldOrPropertyWithValue("keyspace", keyspace); CqlSessionBuilder secondBuilder = context.getBean(CqlSessionBuilder.class);
assertThat(context.getBean(CqlSessionBuilder.class)).hasFieldOrPropertyWithValue("keyspace", null); assertThat(secondBuilder).hasFieldOrPropertyWithValue("keyspace", null);
}); });
} }
......
...@@ -4266,6 +4266,8 @@ Generally, you provide `keyspace-name` and `contact-points` as well the local da ...@@ -4266,6 +4266,8 @@ Generally, you provide `keyspace-name` and `contact-points` as well the local da
You can also register an arbitrary number of beans that implement `DriverConfigLoaderBuilderCustomizer` for more advanced driver customizations. You can also register an arbitrary number of beans that implement `DriverConfigLoaderBuilderCustomizer` for more advanced driver customizations.
The `CqlSession` can be customized with a bean of type `CqlSessionBuilderCustomizer`. The `CqlSession` can be customized with a bean of type `CqlSessionBuilderCustomizer`.
NOTE: If you're using `CqlSessionBuilder` to create multiple `CqlSession` beans, keep in mind the builder is mutable so make sure to inject a fresh copy for each session.
The following code listing shows how to inject a Cassandra bean: The following code listing shows how to inject a Cassandra bean:
[source,java,indent=0] [source,java,indent=0]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment