问题描述
我有 2 个项目(父子)。 父(spring)项目配置了一个 Cassandra CqlSession bean:
//package com.soumav.commonfw.configurations.cassandra
@Bean(name = "astraCassandraCqlSession")
@Primary
public CqlSession cqlSession() throws BusinessException {
CqlSession session = null;
try {
session = CqlSession.builder()
.withCloudSecureConnectBundle(Paths.get(ClassLoader.getSystemResource(astraConfigzipPath).toURI()))
.withAuthCredentials(clientId,clientSecret).build();
} catch (URISyntaxException e) {
log.error("Error Occured: {}",e.toString());
throw new BusinessException(e.toString(),HttpStatus.INTERNAL_SERVER_ERROR);
} catch (Exception e) {
log.error("Error Occured: {}",HttpStatus.INTERNAL_SERVER_ERROR);
}
return session;
}
我将父(spring)项目作为依赖(maven)添加到子(spring-boot)项目中,我在这里使用 Spring-Data-JPA。 当我将孩子中的 cassandra 配置配置为:
//package com.soumav.test.astracassandraapp.config
@Configuration
@EnableCassandraRepositories(basePackages = "com.soumav.test.astracassandraapp.*")
public class TestCassandraConfig extends AbstractCassandraConfiguration {
@Value("${cassandra.keyspacename}")
String keyspacename;
@Autowired
@Qualifier("astraCassandraCqlSession")
CqlSession session;
@Override
protected CqlSession getrequiredSession() {
return this.session;
}
@Override
public String getKeyspaceName() {
return keyspacename;
}
@Override
public SchemaAction getSchemaAction() {
return SchemaAction.CREATE_IF_NOT_EXISTS;
}
@Bean
public CassandraAdminTemplate cassandratemplate() {
session.setSchemaMetadataEnabled(false);
return new CassandraAdminTemplate(session);
}
@Bean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException {
return new CassandraMappingContext();
}
}
我的 Spring-Boot(child) 应用类:
//package com.soumav.test.astracassandraapp
@SpringBootApplication(exclude = { CassandraAutoConfiguration.class,CassandraDataAutoConfiguration.class },scanBasePackages = "com.soumav.*")
public class TestAstraCassandraApplication {
public static void main(String[] args) {
SpringApplication.run(TestAstraCassandraApplication.class,args);
}
}
Repo 接口(子):
//package com.soumav.test.astracassandraapp.repo
@Repository
public interface TestRepo extends CassandraRepository<Student,Integer> {
}
当我运行子项目时,我得到一个异常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraSession' defined in class path resource [com/soumav/test/astracassandraapp/config/TestCassandraConfig.class]: Invocation of init method Failed; nested exception is com.datastax.oss.driver.api.core.AllNodesFailedException: Could not reach any contact point,make sure you've provided valid addresses (showing first 1 nodes,use getAllErrors() for more): Node(endPoint=localhost:9042,hostId=null,hashCode=6a571b5d): [com.datastax.oss.driver.api.core.connection.ConnectionInitException: [s1|control|connecting...] Protocol initialization request,step 1 (OPTIONS): Failed to send request (io.netty.channel.stacklessClosedChannelException)]
已正确导入依赖项(mvn 树)。 我还需要在子项目的自定义 cassandra 配置中覆盖什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)