Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Boot Application Start-up error - Multiple Cassandra Keyspace configuration #1554

Closed
RameshVE123 opened this issue Feb 6, 2025 · 5 comments
Labels
status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged

Comments

@RameshVE123
Copy link

RameshVE123 commented Feb 6, 2025

Hi,

Multiple Cassandra keyspace configuration works well with Spring 2.7.*. However, after upgrading it to Spring Boot 3.0.0, the application fails to start. The error message states that there are 4 CqlSession beans instead of 1 and bean creation exception is thrown.

I've also followed the below link and the reference code given below. Both are not working.

https://tech.willhaben.at/spring-boot-3-2-x-application-using-cassandra-with-multiple-keyspaces-624f12b6dd48
https://github.com/willhaben/spring-data-with-multiple-keyspaces

Any thoughts on this?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 6, 2025
@mp911de
Copy link
Member

mp911de commented Feb 6, 2025

Care to post the full stack trace?

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Feb 6, 2025
@RameshVE123
Copy link
Author

RameshVE123 commented Feb 6, 2025

I will share it. (Building a demo app) Can you please clarify whether Spring 3 supports multiple keyspace configurations with auto-configuration enabled?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 6, 2025
@mp911de
Copy link
Member

mp911de commented Feb 10, 2025

Spring 3 supports multiple keyspace

Not sure what you're talking about. Spring 3 is long out of support. May I assume that you're referring to Spring Boot?

Generally, Spring Boot provides auto-config for resources, one-of-each-kind. This means, one SQL data source, one Mongo client, one Cassandra CqlSession. If you want to use multiple keyspaces, then it depends on your usage pattern. Using CqlSession directly requires you to qualify beans.

Using Cassandra via Spring Data allows you to use SessionFactory. There's a routing variant AbstractRoutingSessionFactory that supports e.g. ThreadLocal selection of backing sessions.

When using Cassandra 5, you can also use different CqlTemplate instances with a single session and set the CqlTemplate.keyspace to associate a specific keyspace with each executed statement.

@mp911de mp911de added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Feb 10, 2025
@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Feb 17, 2025
@RameshVE123
Copy link
Author

Yes. I was referring to Spring Boot 3. I went with the directly using CqlSession with the qualifying beans approach. This works for me. Thanks for the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants