I have the following problem: i want to make a list of Cassandra templates starting from a list of sessions. However the problem is that at runtime i get that the session oject is null. The code i use is the 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 get the following answer from the server:
{
"timestamp": 1505204641753,
"status": 500,
"error": "Internal Server Error",
"exception": "java.lang.IllegalArgumentException",
"message": "Session must not be null",
"path": "/getUser/10/pl"
}