Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -59,6 +60,7 @@
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ Cluster.class, CassandraAdminOperations.class })
@ConditionalOnBean(Cluster.class)
@EnableConfigurationProperties(CassandraProperties.class)
@AutoConfigureAfter(CassandraAutoConfiguration.class)
public class CassandraDataAutoConfiguration {
Expand All @@ -67,8 +69,8 @@ public class CassandraDataAutoConfiguration {

private final Cluster cluster;

public CassandraDataAutoConfiguration(BeanFactory beanFactory,
CassandraProperties properties, Cluster cluster, Environment environment) {
public CassandraDataAutoConfiguration(CassandraProperties properties,
Cluster cluster) {
this.properties = properties;
this.cluster = cluster;
}
Expand Down Expand Up @@ -107,7 +109,7 @@ public CassandraConverter cassandraConverter(CassandraMappingContext mapping,
@Bean
@ConditionalOnMissingBean(Session.class)
public CassandraSessionFactoryBean cassandraSession(Environment environment,
CassandraConverter converter) throws Exception {
CassandraConverter converter) {
CassandraSessionFactoryBean session = new CassandraSessionFactoryBean();
session.setCluster(this.cluster);
session.setConverter(converter);
Expand All @@ -121,7 +123,7 @@ public CassandraSessionFactoryBean cassandraSession(Environment environment,
@Bean
@ConditionalOnMissingBean
public CassandraTemplate cassandraTemplate(Session session,
CassandraConverter converter) throws Exception {
CassandraConverter converter) {
return new CassandraTemplate(session, converter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ public void customConversions() {

}

@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")
Expand Down