我试图在启动spring启动应用程序时在cassandradb中创建表,但它似乎无法创建表。下面是我的配置。我有 @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> {
}
1条答案
按热度按时间ilmyapht1#
我可以通过修改我的
CassandraConfig
上课时间。