我试图在启动spring boot应用程序时在cassandra db中创建表,但它似乎无法创建表。下面是我的配置。我有
@EnableCassandraRepositories
在我的申请课上。默认情况下,我已经创建了我的键空间。所以我要做的只是桌子。
配置
@Configuration
public class CassandraConfig extends AbstractCassandraConfiguration {
@Value("${cassandra.contactpoints}")
private String contactPoints;
@Value("${cassandra.port}")
private int port;
@Value("${cassandra.keyspace}")
private String keySpace;
@Value("${cassandra.basePackages}")
private String basePackages;
@Autowired
private Environment environment;
@Override
protected String getKeyspaceName() {
return keySpace;
}
@Override
@Bean
public CassandraClusterFactoryBean cluster() {
final CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
cluster.setContactPoints(contactPoints);
cluster.setPort(port);
return cluster;
}
@Override
@Bean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException {
return new BasicCassandraMappingContext();
}
}
实体
@Table
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class AssessmentAttemptDetailsEntity implements Serializable {
@PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED)
private String assessmentId;
@PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED)
private String attempid;
}
应用
@SpringBootApplication
@ComponentScan(basePackages = {"com.lte.assessmentanalytics.service","com.lte.assessmentanalytics.config", "com.lte.assessmentanalytics.model", "com.lte.assessmentanalytics.listener"})
@EnableCassandraRepositories("com.lte.assessmentanalytics.model")
public class AssessmentanalyticsApplication {
@Autowired
private AssessmentAttemptRepository assessmentAttemptRepository;
public static void main(String[] args) {
SpringApplication.run(AssessmentanalyticsApplication.class, args);
}
}
知识库
@Repository
public interface AssessmentAttemptRepository extends CassandraRepository<AssessmentAttemptDetailsEntity, Long> {
}