CqlSessionBuilder is a mutable builder, hence this may lead to unexpected situations. Here is a configuration that shows a problem:

@Configuration(proxyBeanMethods = false)
class CassandraConfiguration {

    @Bean
    @DependsOn("session2")
    public CqlSession session1(CqlSessionBuilder builder) {
        return builder.build();
    }

    @Bean
    public CqlSession session2(CqlSessionBuilder builder) {
        return builder.withKeyspace("test").build();
    }

}

This PR adds @Scope(prototype) to avoid such problems 😃

Comment From: snicoll

@nosan thanks for the PR and testing M1 so quickly. Can you share why you'd want to create two CqlSession beans? Last time I checked with @mp911de that didn't seem to be something users would do.

Comment From: nosan

Hi @snicoll, The simple example is: I'd like to have multiple CqlSession that connected to different keyspaces.

Comment From: mp911de

Shouldn't that be rather handled in your bean definitions?

e.g.

class CassandraConfiguration {

    @Bean
    public CqlSession session1(CqlSessionBuilder builder) {
        return builder.withKeyspace("primaryKeySpace").build();
    }

    @Bean
    public CqlSession session2(CqlSessionBuilder builder) {
        return builder.withKeyspace("secondaryKeySpace").build();
    }

}

Comment From: nosan

Thank you for your feedback @mp911de,

Of course, it could be handled on my side, but your example works fine for one property.

From my perspective, it would be nice to have an independent builder in my configuration, so I can do whatever I want with it during CqlSession creation, otherwise, I have to remember what I have changed in builder before.

Comment From: snicoll

That makes sense, thanks for the feedback @nosan