Fix Spring Data Cassandra auto-configure condition

Update `CassandraDataAutoConfiguration` do that it's only applied when
a `Cluster` bean is found.

Fixes gh-16971
pull/17068/head
Dmytro Nosan 6 years ago committed by Phillip Webb
parent ef09ee5dea
commit be435130e6

@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration; import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
import org.springframework.boot.autoconfigure.cassandra.CassandraProperties; import org.springframework.boot.autoconfigure.cassandra.CassandraProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.domain.EntityScanPackages; import org.springframework.boot.autoconfigure.domain.EntityScanPackages;
@ -59,6 +60,7 @@ import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver;
*/ */
@Configuration @Configuration
@ConditionalOnClass({ Cluster.class, CassandraAdminOperations.class }) @ConditionalOnClass({ Cluster.class, CassandraAdminOperations.class })
@ConditionalOnBean(Cluster.class)
@EnableConfigurationProperties(CassandraProperties.class) @EnableConfigurationProperties(CassandraProperties.class)
@AutoConfigureAfter(CassandraAutoConfiguration.class) @AutoConfigureAfter(CassandraAutoConfiguration.class)
public class CassandraDataAutoConfiguration { public class CassandraDataAutoConfiguration {

@ -105,6 +105,15 @@ public class CassandraDataAutoConfigurationTests {
} }
@Test
void clusterDoesNotExist() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(CassandraDataAutoConfiguration.class);
ctx.refresh();
this.context = ctx;
assertThat(ctx.getBeansOfType(Session.class)).isEmpty();
}
public void load(Class<?>... config) { public void load(Class<?>... config) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
TestPropertyValues.of("spring.data.cassandra.keyspaceName:boot_test") TestPropertyValues.of("spring.data.cassandra.keyspaceName:boot_test")

Loading…
Cancel
Save