我的spring-boot / spring-data-cassandra应用程序曾经与Cassandra 2.1运行良好,但当我将Cassandra升级到3.3时,它无法再连接Cassandra服务器了。所以在pom文件中我决定使用一个特定的spring-data-cassandra模块(1.3.2.RELEASE)。我希望新版本的spring-data-cassandra模块将使用最新的Cassandra Java驱动程序。虽然新的spring-data-cassandra模块使用了cassandra驱动程序的更新版本(2.1.5),但是当我运行应用程序时它引发了一个奇怪的例外:
[... CassandraConfig.class];嵌套异常是java.lang.annotation.AnnotationFormatError:默认无效:public abstract java.lang.Class org.springframework.data.cassandra.repository.config.EnableCassandraRepositories.repositoryBaseClass()
有没有人知道为什么会引发此异常?代码在Cassandra 2.1 / spring-data-cassandra 1.1.3中运行良好。
spring-data-cassandra是否支持Cassandra 3.3.0?
下面列出了CassandraConfig类的源代码:
@Configuration
@PropertySource(value={"classpath:/device/repo/cassandra.properties"})
@EnableCassandraRepositories("device.repo")
public class CassandraConfig {
@Autowired
private Environment env;
@Bean
public CassandraClusterFactoryBean cluster() {
CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
cluster.setContactPoints(getContactPoints());
cluster.setPort(getPort());
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(getKeyspaceName());
session.setConverter(converter());
session.setSchemaAction(SchemaAction.NONE);
return session;
}
@Bean
public CassandraOperations cassandraTemplate() throws Exception {
return new CassandraTemplate(session().getObject());
}
protected String getKeyspaceName() {
return env.getProperty("cassandra.keyspace");
}
protected String getContactPoints() {
return env.getProperty("cassandra.contactpoints");
}
protected int getPort() {
return Integer.parseInt(env.getProperty("cassandra.port"));
}
}
非常感谢!