Reputation: 441
We are using Spring data - cassandra and when we run the application without providing configuration, spring boot tries to connect to localhost. Is there a way to stop spring boot from auto connecting?
Thanks in advance :)
Upvotes: 0
Views: 1725
Reputation: 18119
You have multiple ways to achieve that but none of them is just a boolean flag:
Provide @Lazy
Session
/CassandraTemplate
@Bean
's yourself:
@Configuration
public class MyCassandraConfiguration extends CassandraDataAutoConfiguration {
public MyCassandraConfiguration(BeanFactory beanFactory, CassandraProperties properties, Cluster cluster, Environment environment) {
super(beanFactory, properties, cluster, environment);
}
@Override
@Bean
@Lazy
public CassandraSessionFactoryBean session(CassandraConverter converter) throws Exception {
return super.session(converter);
}
@Bean
@Lazy
@Override
public CassandraTemplate cassandraTemplate(Session session, CassandraConverter converter) throws Exception {
return super.cassandraTemplate(session, converter);
}
}
Lazy beans are initialized the first time they are used.
Exclude the CassandraAutoConfiguration. Depending on your setup even more auto-configurations. This approach is rather invasive as required dependencies might get not initialized.
Upvotes: 2