Fix Spring Data Cassandra auto-configure condition
Update `CassandraDataAutoConfiguration` do that it's only applied when a `Cluster` bean is found. Fixes gh-16971
This commit is contained in:
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.cassandra.CassandraAutoConfiguration;
|
||||
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.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScanPackages;
|
||||
|
|
@ -59,6 +60,7 @@ import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver;
|
|||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ Cluster.class, CassandraAdminOperations.class })
|
||||
@ConditionalOnBean(Cluster.class)
|
||||
@EnableConfigurationProperties(CassandraProperties.class)
|
||||
@AutoConfigureAfter(CassandraAutoConfiguration.class)
|
||||
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) {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
TestPropertyValues.of("spring.data.cassandra.keyspaceName:boot_test")
|
||||
|
|
|
|||
Loading…
Reference in New Issue