Problem initiliazing cluster using CassandraClusterFactoryBean

499 views
Skip to first unread message

Christopher Noyes

unread,
Jul 8, 2014, 1:36:39 PM7/8/14
to spring-dat...@googlegroups.com

cluster.getObject() is null, the environment is giving back the right info

I can connect to the cassandra cluster using a non spring application

package com.cjnoyes.locations;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
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.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;

@Configuration
@PropertySource(value = { "classpath:cassandra.properties" })
@EnableCassandraRepositories(basePackages = { "com.cjnoyessw.locations" })
public class CassandraConfig {

  private static final Logger LOG = LoggerFactory.getLogger(CassandraConfig.class);

  @Autowired
  private Environment env;

  @Bean
  public CassandraClusterFactoryBean cluster() {

      
    System.out.println(env.getProperty("cassandra.port"));  
    CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
    cluster.setContactPoints(env.getProperty("cassandra.contactpoints"));
    cluster.setPort(Integer.parseInt(env.getProperty("cassandra.port")));
    try {
        System.out.println(cluster.getObject());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return cluster;
  }

  @Bean
  public CassandraMappingContext mappingContext() {
    return new BasicCassandraMappingContext();
  }

  @Bean
  public CassandraConverter converter() {
    return new MappingCassandraConverter(mappingContext());
  }

  @Bean
  public CassandraSessionFactoryBean session() throws Exception {

    CassandraSessionFactoryBean session = new CassandraSessionFactoryBean();
    session.setCluster(cluster().getObject());
    session.setKeyspaceName(env.getProperty("cassandra.keyspace"));
    session.setConverter(converter());
    session.setSchemaAction(SchemaAction.NONE);
    System.out.println(session.getObject());
    return session;
  }

  @Bean
  public CassandraOperations cassandraTemplate() throws Exception {
    return new CassandraTemplate(session().getObject());
  }
}

Christopher Noyes

unread,
Jul 8, 2014, 1:54:58 PM7/8/14
to spring-dat...@googlegroups.com
It looks like this is a spring boot issue, looks like the afterPropertiesSet was not called

Matthew Adams

unread,
Jul 8, 2014, 2:35:37 PM7/8/14
to Christopher Noyes, spring-dat...@googlegroups.com
It sure seems like this is becoming a FAQ...


--
You received this message because you are subscribed to the Google Groups "Spring Data Cassandra" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spring-data-cass...@googlegroups.com.
To post to this group, send email to spring-dat...@googlegroups.com.
Visit this group at http://groups.google.com/group/spring-data-cassandra.
To view this discussion on the web visit https://groups.google.com/d/msgid/spring-data-cassandra/088d7d0f-518f-4be1-90d3-e0b7374af8a6%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
mailto:mat...@matthewadams.me 

Christopher Noyes

unread,
Jul 8, 2014, 5:30:07 PM7/8/14
to spring-dat...@googlegroups.com
I think building a spring-boot-starter-cassandra would be smart.


On Tuesday, July 8, 2014 1:36:39 PM UTC-4, Christopher Noyes wrote:

Matthew Adams

unread,
Jul 11, 2014, 10:26:29 AM7/11/14
to Christopher Noyes, spring-dat...@googlegroups.com
Can you please share the solution for me?  I haven't had a chance yet to play with Spring Boot... :(


--
You received this message because you are subscribed to the Google Groups "Spring Data Cassandra" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spring-data-cass...@googlegroups.com.
To post to this group, send email to spring-dat...@googlegroups.com.
Visit this group at http://groups.google.com/group/spring-data-cassandra.

For more options, visit https://groups.google.com/d/optout.

Christopher Noyes

unread,
Jul 13, 2014, 4:04:58 PM7/13/14
to Matthew Adams, spring-dat...@googlegroups.com
I did some research into the source code, and spring boot uses a list of sources to load the context.

You need to include in the list classes which are spring configs that you might expect in a web config to get processed automatically.

SpringApplication app = new SpringApplication(DaoSample.class, SampleTask.class, CassandraConfig.class);
        app.run(args);

instead of
SpringApplication.run(SampleTask.class, args)

Matthew Adams

unread,
Jul 29, 2014, 11:47:44 AM7/29/14
to spring-dat...@googlegroups.com, matthe...@scispike.com
Can you enter a JIRA issue for us to create Spring Boot integration for Spring Data Cassandra?  Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to spring-data-cassandra+unsub...@googlegroups.com.

To post to this group, send email to spring-dat...@googlegroups.com.
Visit this group at http://groups.google.com/group/spring-data-cassandra.



--
Matthew Adams
Reply all
Reply to author
Forward
0 new messages