Skip to content

Commit 8fe1830

Browse files
committed
Merge pull request #16971 from nosan
* pr/16971: Polish "Fix Spring Data Cassandra auto-configure condition" Fix Spring Data Cassandra auto-configure condition
2 parents ef09ee5 + 278a086 commit 8fe1830

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@
2828
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2929
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
3030
import org.springframework.boot.autoconfigure.cassandra.CassandraProperties;
31+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
3132
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
3233
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3334
import org.springframework.boot.autoconfigure.domain.EntityScanPackages;
@@ -59,6 +60,7 @@
5960
*/
6061
@Configuration
6162
@ConditionalOnClass({ Cluster.class, CassandraAdminOperations.class })
63+
@ConditionalOnBean(Cluster.class)
6264
@EnableConfigurationProperties(CassandraProperties.class)
6365
@AutoConfigureAfter(CassandraAutoConfiguration.class)
6466
public class CassandraDataAutoConfiguration {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ public void customConversions() {
105105

106106
}
107107

108+
@Test
109+
public void clusterDoesNotExist() {
110+
this.context = new AnnotationConfigApplicationContext(
111+
CassandraDataAutoConfiguration.class);
112+
assertThat(this.context.getBeansOfType(Session.class)).isEmpty();
113+
}
114+
108115
public void load(Class<?>... config) {
109116
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
110117
TestPropertyValues.of("spring.data.cassandra.keyspaceName:boot_test")

0 commit comments

Comments
 (0)