Illustration Image

Connect multiple cassandra DB in spring boot application

Am trying to connect to multiple cassandra DB in springboot application,But when i ran cassandra query from repository class to get data from CassandraConfig2 am getting below error unconfigured table even though table in present in DB

Am trying to connect to multiple cassandra DB in springboot application, below is my cassandra config code

Config 1

@Configuration
@EnableCassandraRepositories(basePackages = "com.example.microservice.cloud.dao.repo1")
public class CassandraConfig1 extends AbstractCassandraConfiguration {

    @Override
    protected String getKeyspaceName() {
        return keySpace;
    }

    @Override
    protected String getContactPoints() {
        return contactPoints;
    }

    @Override
    protected int getPort() {
        return PORT;
    }

    @Bean()
    @Primary
    public CqlSessionFactoryBean cassandraMapSession() {
        final CqlSessionFactoryBean cqlSessionFactoryBean = super.cassandraSession();
        cqlSessionFactoryBean.setContactPoints(contactPoints);
        cqlSessionFactoryBean.setKeyspaceName(keySpace);
        cqlSessionFactoryBean.setPort(PORT);
        cqlSessionFactoryBean.setUsername(cassandraUsername);
        cqlSessionFactoryBean.setPassword(cassandraPassword);
        return cqlSessionFactoryBean;
    }

    @Override
    public CqlSessionFactoryBean cassandraSession() {
        return cassandraMapSession();
    }
}

Config 2

@Configuration
@EnableCassandraRepositories(basePackages = "com.example.microservice.cloud.dao.repo2")
public class CassandraConfig2 extends AbstractCassandraConfiguration {

    @Override
    protected String getKeyspaceName() {
        return keySpace;
    }

    @Override
    protected String getContactPoints() {
        return contactPoints;
    }

    @Override
    protected int getPort() {
        return PORT;
    }

    @Bean()
    public CqlSessionFactoryBean cassandraMapSession() {
        final CqlSessionFactoryBean cqlSessionFactoryBean = super.cassandraSession();
        cqlSessionFactoryBean.setContactPoints(contactPoints);
        cqlSessionFactoryBean.setKeyspaceName(keySpace);
        cqlSessionFactoryBean.setPort(PORT);
        cqlSessionFactoryBean.setUsername(cassandraUsername);
        cqlSessionFactoryBean.setPassword(cassandraPassword);
        return cqlSessionFactoryBean;
    }

    @Override
    public CqlSessionFactoryBean cassandraSession() {
        return cassandraMapSession();
    }
}

But when i ran cassandra query from repository class to get data from CassandraConfig2 am getting below error unconfigured table even though table in present in DB

need help here

Become part of our
growing community!
Welcome to Planet Cassandra, a community for Apache Cassandra®! We're a passionate and dedicated group of users, developers, and enthusiasts who are working together to make Cassandra the best it can be. Whether you're just getting started with Cassandra or you're an experienced user, there's a place for you in our community.
A dinosaur
Planet Cassandra is a service for the Apache Cassandra® user community to share with each other. From tutorials and guides, to discussions and updates, we're here to help you get the most out of Cassandra. Connect with us and become part of our growing community today.
© 2009-2023 The Apache Software Foundation under the terms of the Apache License 2.0. Apache, the Apache feather logo, Apache Cassandra, Cassandra, and the Cassandra logo, are either registered trademarks or trademarks of The Apache Software Foundation. Sponsored by Anant Corporation and Datastax, and Developed by Anant Corporation.

Get Involved with Planet Cassandra!

We believe that the power of the Planet Cassandra community lies in the contributions of its members. Do you have content, articles, videos, or use cases you want to share with the world?