2

我正在使用 Spring Boot 设置一个小项目spring-data-cassandra

我意识到当我在 @Table 对象上有 joda time Datetime 时,我的测试会中断。堆栈显示如下错误:

Caused by: org.springframework.data.cassandra.mapping.VerifierMappingExceptions: org.joda.time.Chronology: Cassandra entities must have the @Table, @Persistent or @PrimaryKeyClass Annotation

我的配置如下:

@Configuration
@EnableCassandraRepositories(basePackages ="com.myproject.cassandra.repository")
@ComponentScan(basePackages = "com.myproject.cassandra")
@EnableAutoConfiguration
class CassandraConfiguration {
   private static ConfigContext confitConfig = ConfigContext.lookup();
   //private static AdminContext confitAdmin = AdminContext.lookup();
   DataSource cassandraDataSource

   static {
      confitConfig.register(DataSource.class);
   }

   Collection<DataSource> dataSources = confitConfig.list(DataSource.class)

   CassandraConfiguration() {
      cassandraDataSource = new DataSource();

      dataSources.each { d -> d.name == "Cassandra"
         cassandraDataSource = d
      }
   }

   @Bean
   public CassandraClusterFactoryBean cluster(){
      CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean()
      cluster.setContactPoints(cassandraDataSource.host)
      cluster.setPort(cassandraDataSource.port)
      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.setConverter(converter())
      session.setKeyspaceName(cassandraDataSource.database)
      session.setSchemaAction(SchemaAction.NONE)
      return session;
   }

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

会不会因为我正在使用而发生BasicCassandraMappingContext?如何解决这个问题?

4

0 回答 0