diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java index 0798071967e..be58c02228f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java @@ -40,6 +40,7 @@ import org.springframework.util.StringUtils; * @author Phillip Webb * @author EddĂș MelĂ©ndez * @author Stephane Nicoll + * @auther Steffen F. Qvistgaard * @since 1.3.0 */ @Configuration(proxyBeanMethods = false) @@ -47,10 +48,17 @@ import org.springframework.util.StringUtils; @EnableConfigurationProperties(CassandraProperties.class) public class CassandraAutoConfiguration { + @Bean + @ConditionalOnMissingBean + public CassandraClusterFactory cassandraClusterFactory() { + return new CassandraClusterFactoryImpl(); + } + @Bean @ConditionalOnMissingBean public Cluster cassandraCluster(CassandraProperties properties, - ObjectProvider builderCustomizers) { + ObjectProvider builderCustomizers, + CassandraClusterFactory clusterFactory) { PropertyMapper map = PropertyMapper.get(); Cluster.Builder builder = Cluster.builder() .withClusterName(properties.getClusterName()) @@ -71,7 +79,8 @@ public class CassandraAutoConfiguration { .toCall(builder::withoutJMXReporting); builderCustomizers.orderedStream() .forEach((customizer) -> customizer.customize(builder)); - return builder.build(); + + return clusterFactory.build(builder); } private QueryOptions getQueryOptions(CassandraProperties properties) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraClusterFactory.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraClusterFactory.java new file mode 100644 index 00000000000..a07c55edb9c --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraClusterFactory.java @@ -0,0 +1,34 @@ +/* + * Copyright 2012-2019 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.cassandra; + +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Cluster.Initializer; + +/** + * Cassandra Cluster Factory Interface. + * + * This interface allows the default cassandra cluster builder to be overwritten + * + * @auther Steffen F. Qvistgaard + * @since 2.2.0 + */ +public interface CassandraClusterFactory { + + Cluster build(Initializer initializer); + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraClusterFactoryImpl.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraClusterFactoryImpl.java new file mode 100644 index 00000000000..2b858f9f92e --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraClusterFactoryImpl.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2019 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.cassandra; + +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Cluster.Initializer; + +/** + * Default Cassandra Cluster Factory Implementation. + * + * @auther Steffen F. Qvistgaard + * @since 2.2.0 + */ +public class CassandraClusterFactoryImpl implements CassandraClusterFactory { + + @Override + public Cluster build(final Initializer initializer) { + return Cluster.buildFrom(initializer); + } + +}