Cassandra session null at runtime -
i have following problem: want make list of cassandra templates starting list of sessions. problem @ runtime session oject null. code use following:
import java.util.arraylist; import java.util.list; import org.springframework.beans.factory.annotation.autowired; import org.springframework.beans.factory.annotation.qualifier; import org.springframework.data.cassandra.config.cassandraclusterfactorybean; import org.springframework.data.cassandra.config.cassandrasessionfactorybean; import org.springframework.data.cassandra.config.schemaaction; import org.springframework.data.cassandra.convert.cassandraconverter; import org.springframework.data.cassandra.core.cassandraoperations; import org.springframework.data.cassandra.core.cassandratemplate; import org.springframework.stereotype.component; @component public class keyspacesession { @autowired @qualifier("cluster") cassandraclusterfactorybean cluster; @autowired @qualifier("converter") cassandraconverter converter; public list<cassandraoperations> gettemplates(){ list<cassandraoperations> listoftemplates = new arraylist<>(); for(cassandrakeyspaces keyspace : cassandrakeyspaces.values()){ cassandrasessionfactorybean session = new cassandrasessionfactorybean(); session.setcluster(cluster.getobject()); session.setkeyspacename(keyspace.getkeyspace()); session.setconverter(converter); session.setschemaaction(schemaaction.create_if_not_exists); cassandraoperations op = new cassandratemplate(session.getobject()); listoftemplates.add(op); } return listoftemplates; } }
i following answer server:
{ "timestamp": 1505204641753, "status": 500, "error": "internal server error", "exception": "java.lang.illegalargumentexception", "message": "session must not null", "path": "/getuser/10/pl" }
cassandrasessionfactorybean
requires initialization after you've set properties. call cassandrasessionfactorybean.afterpropertiesset()
before obtaining session
. need clean sessions on application shutdown.
ideally, register beandefinition
s each session
, cassandraoperations
bean want create.
references:
Comments
Post a Comment