Facing an issue with Spring boot 3.2.x with cassandra multiple keyspaces

{"@timestamp":"2025-01-30 13:40:32.256 GMT","level":"WARN","thread":"main","logger":"o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext","msgType":"SERVICE-MSG","sMsg":{"msg":"Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraTemplate' defined in class path resource [com/art/config/ArtConfig.class]: No matching factory method found on class [com.art.config.ArtConfig]: factory bean 'artConfig'; factory method 'cassandraTemplate()'. Check that a method with the specified name exists and that it is non-static."},"seq":76,"format":"nf-v1.0"}
{"@timestamp":"2025-01-30 13:40:48.896 GMT","level":"ERROR","thread":"main","logger":"o.s.b.SpringApplication","msgType":"SERVICE-MSG-ERROR","sMsg":{"msg":"Application run failed"},"exTrace":"org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraTemplate' defined in class path resource [com/art/config/ArtConfig.class]: No matching factory method found on class [com.aer.config.ArtConfig]: factory bean 'artConfig'; factory method 'cassandraTemplate()'. Check that a method with the specified name exists and that it is non-static.\r\n\tat org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:616)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1335)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1165)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562)\r\n\tat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326)\r\n\tat org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324)\r\n\tat org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)\r\n\tat org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975)\r\n\t... 9 frames truncated\r\n","exHash":"c05c9930","seq":80,"format":"nf-v1.0"}

Here is my poc code

@Configuration
@ConfigurationProperties("spring.cassandra.art")
@EnableCassandraRepositories(basePackages = "com.art.repository", cassandraTemplateRef = "artTemplate")
public class ArtConfig extends BaseConfig
{
    private static final Logger log = LoggerFactory.getLogger(ArtConfig.class);

    @Value("${spring.cassandra.art.keyspace}")
    private String keyspace;

    @Value("${spring.cassandra.art.username}")
    private String username;  

    @Value("${spring.cassandra.art.password}")
    private String password;      

    @Override
    protected String getSessionName() 
    {
        return "artCluster";
    }

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

    @Override
    protected SessionBuilderConfigurer getSessionBuilderConfigurer() 
    {
        return cqlSessionBuilder -> {
            cqlSessionBuilder
                .withConfigLoader(getDriverConfigLoader());

            if(isSslEnabled())
            {
                TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
                SSLContext sslContext = null;
                try 
                {
                    sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();

                    cqlSessionBuilder.withSslContext(sslContext);
                } 
                catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) 
                {
                    log.error("artConfig ssl context setup ::", e);
                }
            }

            return cqlSessionBuilder;
        };
    }     

    @Bean(name = "artSession")
    @Override
    public CqlSessionFactoryBean cassandraSession() 
    {
        //super session should be called only once   
        CqlSessionFactoryBean cassandraSession = super.cassandraSession();
        cassandraSession.setContactPoints(getContactPoints());
        cassandraSession.setPort(getPort());
        cassandraSession.setLocalDatacenter(getLocalDataCenter());
        cassandraSession.setUsername(username);
        cassandraSession.setPassword(password);

        return cassandraSession;
    }

     @Override
     @Primary    
     @Bean(name = "artTemplate")
     public CassandraAdminTemplate cassandraTemplate() 
     {
         return new CassandraAdminTemplate(this.cassandraSession().getObject(), cassandraConverter());
     }

     @Override
     public CqlTemplate cqlTemplate() 
     {
        CqlTemplate cqlTemplate = super.cqlTemplate();

        cqlTemplate.setConsistencyLevel(getConsistencyLevel());
        cqlTemplate.setSerialConsistencyLevel(getConsistencyLevel());

        return cqlTemplate;  
     }   
}



public abstract class BaseConfig extends AbstractCassandraConfiguration
{
    @Value("${spring.cassandra.local-datacenter}")
    private String dataCenter;

    @Value("${spring.cassandra.contact-points}")
    private String contactPoints;

    @Value("${spring.cassandra.port}")
    private int port;

    @Value("${spring.cassandra.request.consistency}")
    private ConsistencyLevel level;  

    @Value("${spring.cassandra.ssl}")
    private String sslEnable;

    @Value("${cassandra.ttl:1234}")
    private int ttl;

    @Override
    protected String getLocalDataCenter() 
    {
        return dataCenter;
    }   

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

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

    @Override
    public SchemaAction getSchemaAction() 
    {
        return SchemaAction.NONE;
    }

    public int getTtl() 
    {
        return ttl;
    }

    protected ConsistencyLevel getConsistencyLevel() 
    {
        return level;
    }    

    protected boolean isSslEnabled() 
    {
        return Boolean.parseBoolean(sslEnable);
    }   

    protected DriverConfigLoader getDriverConfigLoader() 
    {
        return DriverConfigLoader.programmaticBuilder()
            .withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofMillis(getTtl()))
            .withDuration(DefaultDriverOption.CONNECTION_CONNECT_TIMEOUT, Duration.ofMillis(getTtl()))
            .build();
    }   
}

Comment From: wilkinsona

Spring Boot 3.2.x is no longer supported. Furthermore, it's not clear to me why you believe that this is a Spring Boot problem. You appear to be configuring Spring Data Cassandra yourself, rather than relying on Spring Boot's auto-configuration, so it doesn't look like Spring Boot is really involved here.

If you're looking for some help with setting up Spring Data Cassandra using multiple keyspaces, I would first recommend upgrading to a supported version of Spring Boot and Spring Data Cassandra. If that doesn't help, I would then ask a question on Stack Overflow, providing a complete yet minimal sample that reproduces the problem. I would also include the error message in an easy-to-read (non-JSON) format.

Comment From: keshavanyala

Apologies if it's not really an issue with Spring Boot, but previously we were using Spring Boot 2.7.x, and the same code and configuration were working fine. After migrating to Spring Boot 3.2.x, it's giving the above error. I am unable to fix the error. If possible Could you please help us with some suggestions to fix the issue, or if possible, provide a sample project that integrates Spring Boot 3.2.x with Cassandra multiple keyspaces?

Comment From: wilkinsona

Sorry, we're only a small team and we do not have enough time to provide that level of support. Someone on Stack Overflow may be able to help you. You can increase the changes of someone having time to help you by making it as easy as possible for them to do so. Create a complete yet minimal sample that's quick and easy for them to run, for example.