我有一个springboot应用程序,我正在连接到cassandradb。
我的pom.xml:
parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
cassandraconfig定义:
@Configuration
@PropertySource("file:///Users/s1b03vf/Work/carrierhub/cass.properties")
@ConfigurationProperties()
@EnableCassandraRepositories(basePackageClasses = {MCSEDistributorRepository.class})
public class MSCECassandraConfig {
protected String contactPoints;
protected int port;
protected String username;
protected String password;
protected String keyspace;
@Override
protected AuthProvider getAuthProvider() {
return new PlainTextAuthProvider(username, password);
}
@Override
protected String getKeyspaceName() {
return keyspace;
}
@Override
protected String getContactPoints() {
return contactPoints;
}
@Override
protected int getPort() {
return port;
}
@Override
public String[] getEntityBasePackages() {
return new String[]{"com.example.demo.entity.cassandra"};
}
}
存储库类:
@Repository
public interface MCSEDistributorRepository extends CassandraRepository<MCSEDistributor, String> {
}
实体类:
@Table("mcse_offer")
public class MCSEDistributor {
@Column
@PrimaryKey
private int id;
@Column
private String name;
}
现在,当我启动应用程序时,遇到以下错误:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'documentationPluginsBootstrapper' defined in URL [jar:file:/Users/s1b03vf/.m2/repository/io/springfox/springfox-spring-web/2.9.2/springfox-spring-web-2.9.2.jar!/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstrapper.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/Users/s1b03vf/.m2/repository/io/springfox/springfox-spring-web/2.9.2/springfox-spring-web-2.9.2.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Unsatisfied dependency expressed through method 'requestMappingHandlerMapping' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MCSEDistributorRepository': Cannot resolve reference to bean 'cassandraTemplate' while setting bean property 'cassandraTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraTemplate' defined in class path resource [com/example/demo/config/MSCECassandraConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.core.CassandraAdminTemplate]: Factory method 'cassandraTemplate' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/example/demo/config/MSCECassandraConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.SessionFactory]: Factory method 'sessionFactory' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'session' defined in class path resource [com/example/demo/config/MSCECassandraConfig.class]: Invocation of init method failed; nested exception is com.datastax.driver.core.exceptions.DriverInternalError: Unexpected exception thrown
它指出了cassandratemplate和sessionfactory的依赖关系和bean创建问题。我对使用spring数据还不熟悉,所以不确定这里缺少什么。
从启动日志中,我可以看到它正在使用以下驱动程序版本:
2020-06-08 22:44:57.782 INFO 42129 --- [ restartedMain] com.datastax.driver.core : DataStax Java driver 3.7.2 for Apache Cassandra
3条答案
按热度按时间ibps3vxo1#
你的电脑出毛病了
@configuration
班级。它没有@bean
注解。看看这个例子,Cassandra@configuration
上课地点:https://www.baeldung.com/spring-data-cassandra-tutorial这里还解释了如何配置存储库和表。
j2cgzkjk2#
尝试调用super,然后设置所需的属性
rggaifut3#
解决了问题。问题是cassandraconfig类缺少以下内容:
加上这个,它开始运行良好。