Accessing the bean created

42 views
Skip to first unread message

jayant chauhan

unread,
Jun 16, 2014, 12:47:22 PM6/16/14
to spring-dat...@googlegroups.com
I tried the basic implementation in my application:
    @Override
    protected String getKeyspaceName() {
        return KEYSPACE;
    }

    @Bean
    public CassandraOperations CassandraTemplate() {
return new CassandraOperations(session().getObject());
}
I am able to connect to my keyspace present on the remote node i am trying to connect to. I can see it from the logs in my app. Then i tried accessing the bean created in my DAO layer to query the Database by doing autowiring. As it is given in the readme of Spring data Cassandra example. I used something similar to the below code in my app.
@Autowired
    private CassandraOperations CassandraTemplate;

    public Integer getCount() throws DataAccessException {

        String cql = "select count(*) from table_name where id='12345'";

        Integer count = CassandraTemplate.queryForObject(cql, Integer.class);
log.info("Row Count is -> " + count); return count; }
Autowiring is happening but the bean i am trying to access is coming null. Is there anything i am missing in implementing this? please provide your inputs.

David Webb (Prowave)

unread,
Jun 16, 2014, 12:53:16 PM6/16/14
to jayant chauhan, spring-dat...@googlegroups.com
If CassandraTemplate is null in your DAO pattern, then autowiring isn’t happening.  You might also want to name your variable “CassandraTemplate different from a concrete class name for clarity.  Without knowing more about how your spring context is configured and initialized, there isn’t much more I can offer.

From: jayant chauhan <jayan...@gmail.com>
Date: Monday, June 16, 2014 at 12:47 PM
To: "spring-dat...@googlegroups.com" <spring-dat...@googlegroups.com>
Subject: Accessing the bean created

CassandraTemplate
Reply all
Reply to author
Forward
0 new messages