I am working on a POC -- creating a REST service to perform basic CRUD operations into Cassandra.
I am using spring-data-cassandra and spring-data-rest-web-mvc
I have created three Java files
Contract.java -> Entity description of the Cassandra column family (Table)
ContractRepository.java -> Repository information
Application.java -> Contains the main
Since there are no specific tutorial for Cassandra (as yet) I am trying to replicate the MongoDb description with Cassandra.
I am trying to run the application without any configuration files and also using spring-boot -- similar to how the tutorials are done with Mongo.
I am using maven to do the compile/build and run. I am starting the run using "mvn spring-boot:run".
I am getting a run time exception while trying to run this.
The key error is the following:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contractRepository': Cannot resolve reference to bean 'cassandraTemplate' while setting bean property 'cassandraTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraTemplate' defined in class cass_test3.Application: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null
The cassandraTemplate bean is not being created!
Here is the code
Application.java
package cass_test3;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
@Configuration
@EnableCassandraRepositories
@Import(RepositoryRestMvcConfiguration.class)
@EnableAutoConfiguration
public class Application{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Contract.java
package cass_test3;
import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Column;
import org.springframework.data.cassandra.mapping.Table;
@Table(value="contracts")
public class Contract {
@PrimaryKey(value="id")
@Column(value="id")
private String id;
public String getId() {
return id;
}
public void setId(String id) {
}
}
ContractRepository.java
package cass_test3;
import org.springframework.data.cassandra.repository.CassandraRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
@RepositoryRestResource(collectionResourceRel = "contract", path = "contract")
public interface ContractRepository extends CassandraRepository<Contract> {
Contract findById(@Param("id") String id);
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<modelVersion>4.0.0</modelVersion>
<groupId>cass-test3</groupId>
<artifactId>cass-test3</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.2.RELEASE</version>
</parent>
<repositories>
<repository>
<id>spring-libs-snapshot</id>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
<version>2.1.0.RC1</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>1.0.0.RC1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
</dependencies>
</project>
I understand that a default cassandraTemplate bean should be created at run time using the standard defaults for the connection to ContractRepository.
Somehow that is not being created. Do I need to explicitly initialize the cassandraTemplate? If so how do I do it?
Thanks
Jega