Skip to content

Spring Boot 3: AbstractCassandraConfiguration not creating cassandraTemplate with different bean names #1411

@sathishnune

Description

@sathishnune

After Spring Boot 3 upgrade, AbstractCassandraConfiguration failed to create a cassandraTemplate with different bean name.

@Configuration
@EnableCassandraRepositories
public class TestCassandraConfig extends AbstractCassandraConfiguration {

    @Override
    protected String getKeyspaceName() {
        return "keyspace";
    }

    @Override
    protected String getContactPoints() {
        return "localhost:9042";
    }

    @Override
    protected String getLocalDataCenter() {
        return "datacenter1";
    }

    @Override
    @Bean("cassandraHealthCheckSession")
    public CqlSessionFactoryBean cassandraSession() {
        CqlSessionFactoryBean cassandraSession = super.cassandraSession();
        cassandraSession.setUsername("username");
        cassandraSession.setPassword("password");

        return cassandraSession;
    }

    @Bean("cassandraHealthCheckTemplate")
    @Override
    public CassandraAdminTemplate cassandraTemplate() {
        return new CassandraAdminTemplate(getRequiredSession(), requireBeanOfType(CassandraConverter.class));
    }

    @Bean
    @Override
    public SessionFactoryFactoryBean cassandraSessionFactory(CqlSession cassandraHealthCheckSession) {
        return super.cassandraSessionFactory(cassandraHealthCheckSession);
    }

    @Override
    protected CqlSession getRequiredSession() {
        return getBeanFactory().getBean("cassandraHealthCheckSession", CqlSession.class);
    }

    @Override
    protected SessionFactory getRequiredSessionFactory() {
        return this::getRequiredSession;
    }
}

Error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraTemplate' defined in class path resource [com/example/cassandratest/config/TestCassandraConfig.class]: No matching factory method found on class [com.example.cassandratest.config.TestCassandraConfig]: factory bean 'testCassandraConfig'; factory method 'cassandraTemplate()'. Check that a method with the specified name exists and that it is non-static.

I need multiple templates as I need to connect to multiple key spaces. Is there a way to make it work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions