我正在尝试几个概念证明来测试时间序列数据。我从spring网站上取样并在eclipse上配置它。
以下是一些细节:
Cassandra Version ** - 3.0.9 Spring数据cassandra版本 - 1.0.0.RELEASE DataStax java驱动程序core-cassandra-driver-core-3.1.2
我正在执行以下代码:
Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9042).build();
Session session = cluster.connect("axiaglobal");
CassandraOperations cassandraOps = new CassandraTemplate(session);
cassandraOps.insert(new Person("1234567890", "David", 40));
和Person.java如下:
@Table
public class Person {
@PrimaryKey
private String id;
private String name;
private int age;
public Person(String id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
@Override
public String toString() {
return "Person [id=" + id + ", name=" + name + ", age=" + age + "]";
}
}
在执行代码时,我得到以下异常:
Exception in thread "main" java.lang.NoSuchMethodError: com.datastax.driver.core.DataType.asJavaClass()Ljava/lang/Class;
at org.springframework.data.cassandra.mapping.CassandraSimpleTypeHolder.<clinit>(CassandraSimpleTypeHolder.java:62)
at org.springframework.data.cassandra.mapping.BasicCassandraMappingContext.<init>(BasicCassandraMappingContext.java:73)
at org.springframework.data.cassandra.convert.MappingCassandraConverter.<init>(MappingCassandraConverter.java:77)
at org.springframework.data.cassandra.core.CassandraTemplate.<init>(CassandraTemplate.java:75)
at com.axia.global.dao.cassandra.service.CassandraApp.main(CassandraApp.java:26)
有人可以帮我解决一些建议或指示吗?
答案 0 :(得分:0)
更改pom文件如下解决了我的问题:
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit-spring</artifactId>
<version>3.1.1.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit</artifactId>
<classifier>shaded</classifier>
<version>3.1.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.1.1</version>
<optional>true</optional>
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>com.google.guava</groupId>-->
<!--<artifactId>guava</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->
</dependency>