Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to block Cassandra from trying to connect automatically

I have this project where I'm trying to connect to different DB types based on configuration. I have it working for Mongo and MySQL and switch by loading Beans by using @ConditionalOnProperty(name = "settings.data.source", havingValue = "mongodb")

Now I want to add Cassandra, but once I added the following dependency to my pom, it starts trying to connect to Cassandra nodes on localhost.

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-cassandra</artifactId>
    </dependency>

I want to have more control over when the Cassandra resources are loaded.

It doesn't try to connect automatically when I added Mongo dependencies:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>

Anyone familiar with this behavior? How can I control this? I don't always need a Cassandra connection...

like image 207
Denn0 Avatar asked Apr 18 '17 18:04

Denn0


People also ask

How do I turn off auto-configuration?

If you find that specific auto-configure classes are being applied that you don't want, you can use the exclude attribute of @EnableAutoConfiguration to disable them. If the class is not on the classpath, you can use the excludeName attribute of the annotation and specify the fully qualified name instead.

How disable auto-configuration in spring boot which attribute is used?

3. Disable Using Property File. We can also disable auto-configuration using the property file.


1 Answers

You may disable Cassandra auto configuration,

@SpringBootApplication
@EnableAutoConfiguration(exclude={CassandraDataAutoConfiguration.class})
like image 102
Deepak Avatar answered Sep 22 '22 09:09

Deepak