parent
2a01c0262b
commit
c8105413b9
|
@ -44,6 +44,7 @@ import org.springframework.boot.context.properties.PropertyMapper;
|
|||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for Cassandra.
|
||||
|
@ -69,6 +70,7 @@ public class CassandraAutoConfiguration {
|
|||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@Scope("prototype")
|
||||
public CqlSessionBuilder cassandraSessionBuilder(CassandraProperties properties,
|
||||
DriverConfigLoader driverConfigLoader, ObjectProvider<CqlSessionBuilderCustomizer> builderCustomizers) {
|
||||
CqlSessionBuilder builder = CqlSession.builder().withConfigLoader(driverConfigLoader);
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.boot.autoconfigure.cassandra;
|
||||
|
||||
import com.datastax.oss.driver.api.core.CqlIdentifier;
|
||||
import com.datastax.oss.driver.api.core.CqlSessionBuilder;
|
||||
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
|
||||
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
|
||||
import com.datastax.oss.driver.api.core.config.DriverExecutionProfile;
|
||||
|
@ -42,6 +44,17 @@ class CassandraAutoConfigurationTests {
|
|||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(CassandraAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
void cqlSessionBuilderThreadSafe() {
|
||||
this.contextRunner.run((context) -> {
|
||||
CqlIdentifier keyspace = CqlIdentifier.fromCql("test");
|
||||
assertThat(context).hasSingleBean(CqlSessionBuilder.class);
|
||||
assertThat(context.getBean(CqlSessionBuilder.class).withKeyspace(keyspace))
|
||||
.hasFieldOrPropertyWithValue("keyspace", keyspace);
|
||||
assertThat(context.getBean(CqlSessionBuilder.class)).hasFieldOrPropertyWithValue("keyspace", null);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void driverConfigLoaderWithDefaultConfiguration() {
|
||||
this.contextRunner.run((context) -> {
|
||||
|
|
Loading…
Reference in New Issue