2

当我尝试在大多数版本的 Spring Boot (1.4) 中使用 Spring Data Cassandra 时遇到问题。

这似乎是一个maven依赖问题,它没有加载最新版本的Cassandra驱动程序。请问有什么解决方案可以解决这个问题吗?提前致谢![

编辑在整合了mp911de提出的解决方案之后

] 感谢您的回复,我按照您的建议设置了 cassandra-driver,但我仍然有错误,这是完整的堆栈跟踪。

08:46:41.691| ERROR | Application startup failed                                                                                                                             | org.springxxamework.boot.SpringApplication.handleRunFailure(SpringApplication.java:827)
org.springxxamework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraMapping' defined in class path resource [xx/xxx/xxx/cap/web/config/CasssandraConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springxxamework.beans.BeanInstantiationException: Failed to instantiate [org.springxxamework.data.cassandra.mapping.CassandraMappingContext]: Factory method 'cassandraMapping' threw exception; nested exception is java.lang.NoSuchMethodError: com.datastax.driver.core.DataType.asJavaClass()Ljava/lang/Class;
    at org.springxxamework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springxxamework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springxxamework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springxxamework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springxxamework.context.support.AbstractApplicationContext.rexxesh(AbstractApplicationContext.java:538)
    at org.springxxamework.boot.context.embedded.EmbeddedWebApplicationContext.rexxesh(EmbeddedWebApplicationContext.java:118)
    at org.springxxamework.boot.SpringApplication.rexxesh(SpringApplication.java:766)
    at org.springxxamework.boot.SpringApplication.createAndRexxeshContext(SpringApplication.java:361)
    at org.springxxamework.boot.SpringApplication.run(SpringApplication.java:307)
    at xx.xxx.xxx.cap.web.Application.main(Application.java:66)
Caused by: org.springxxamework.beans.BeanInstantiationException: Failed to instantiate [org.springxxamework.data.cassandra.mapping.CassandraMappingContext]: Factory method 'cassandraMapping' threw exception; nested exception is java.lang.NoSuchMethodError: com.datastax.driver.core.DataType.asJavaClass()Ljava/lang/Class;
    at org.springxxamework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
    at org.springxxamework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    ... 16 common xxames omitted
Caused by: java.lang.NoSuchMethodError: com.datastax.driver.core.DataType.asJavaClass()Ljava/lang/Class;
    at org.springxxamework.data.cassandra.mapping.CassandraSimpleTypeHolder.<clinit>(CassandraSimpleTypeHolder.java:62)
    at org.springxxamework.data.cassandra.mapping.BasicCassandraMappingContext.<init>(BasicCassandraMappingContext.java:73)
    at xx.xxx.xxx.cap.web.config.CasssandraConfiguration.cassandraMapping(CasssandraConfiguration.java:36)
    at xx.xxx.xxx.cap.web.config.CasssandraConfiguration$$EnhancerBySpringCGLIB$$9133c12d.CGLIB$cassandraMapping$3(<generated>)
    at xx.xxx.xxx.cap.web.config.CasssandraConfiguration$$EnhancerBySpringCGLIB$$9133c12d$$FastClassBySpringCGLIB$$ec58ee73.invoke(<generated>)
    at org.springxxamework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springxxamework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
    at xx.xxx.xxx.cap.web.config.CasssandraConfiguration$$EnhancerBySpringCGLIB$$9133c12d.cassandraMapping(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springxxamework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 17 common xxames omitted
08:46:41.709| ERROR | Error handling failed                                                                                                                                  | org.springxxamework.boot.SpringApplicationRunListeners.callFinishedListener(SpringApplicationRunListeners.java:86)
org.springxxamework.beans.factory.BeanCreationException: Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springxxamework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Initialization of bean failed; nested exception is org.springxxamework.beans.factory.BeanCreationException: Error creating bean with name 'metaDataSourceAdvisor': Cannot resolve reference to bean 'methodSecurityMetadataSource' while setting constructor argument; nested exception is org.springxxamework.beans.factory.BeanCreationException: Error creating bean with name 'org.springxxamework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration': Initialization of bean failed; nested exception is org.springxxamework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springxxamework.context.annotation.ConfigurationClassPostProcessor.importRegistry' is defined
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springxxamework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springxxamework.context.event.AbstractApplicationEventMulticaster.retrieveApplicationListeners(AbstractApplicationEventMulticaster.java:228)
    at org.springxxamework.context.event.AbstractApplicationEventMulticaster.getApplicationListeners(AbstractApplicationEventMulticaster.java:185)
    at org.springxxamework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    at org.springxxamework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:121)
    at org.springxxamework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:111)
    at org.springxxamework.boot.context.event.EventPublishingRunListener.finished(EventPublishingRunListener.java:98)
    at org.springxxamework.boot.SpringApplicationRunListeners.callFinishedListener(SpringApplicationRunListeners.java:79)
    at org.springxxamework.boot.SpringApplicationRunListeners.finished(SpringApplicationRunListeners.java:72)
    at org.springxxamework.boot.SpringApplication.handleRunFailure(SpringApplication.java:833)
    at org.springxxamework.boot.SpringApplication.run(SpringApplication.java:318)
    at xx.xxx.xxx.cap.web.Application.main(Application.java:66)
Caused by: org.springxxamework.beans.factory.BeanCreationException: Error creating bean with name 'metaDataSourceAdvisor': Cannot resolve reference to bean 'methodSecurityMetadataSource' while setting constructor argument; nested exception is org.springxxamework.beans.factory.BeanCreationException: Error creating bean with name 'org.springxxamework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration': Initialization of bean failed; nested exception is org.springxxamework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springxxamework.context.annotation.ConfigurationClassPostProcessor.importRegistry' is defined
    at org.springxxamework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
    at org.springxxamework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
    at org.springxxamework.beans.factory.support.ConstructorResolver.resolvePreparedArguments(ConstructorResolver.java:786)
    at org.springxxamework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:123)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1143)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1034)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springxxamework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springxxamework.aop.xxamework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:92)
    at org.springxxamework.aop.xxamework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:101)
    at org.springxxamework.aop.xxamework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:87)
    at org.springxxamework.aop.xxamework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
    at org.springxxamework.aop.xxamework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:346)
    at org.springxxamework.aop.xxamework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:298)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    ... 16 common xxames omitted
Caused by: org.springxxamework.beans.factory.BeanCreationException: Error creating bean with name 'org.springxxamework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration': Initialization of bean failed; nested exception is org.springxxamework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springxxamework.context.annotation.ConfigurationClassPostProcessor.importRegistry' is defined
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springxxamework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springxxamework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springxxamework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springxxamework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
    ... 36 common xxames omitted
Caused by: org.springxxamework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springxxamework.context.annotation.ConfigurationClassPostProcessor.importRegistry' is defined
    at org.springxxamework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:698)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1175)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:284)
    at org.springxxamework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    at org.springxxamework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor.postProcessBeforeInitialization(ConfigurationClassPostProcessor.java:439)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
    at org.springxxamework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    ... 51 common xxames omittedende
4

1 回答 1

7

没错,带有 Spring Data Cassandra 1.4.2 的 Spring Boot 1.4 与 Cassandra 3.0 不兼容。

Spring Data 1.5(将)与 Cassandra 3.0 兼容。我们已经发布了一个里程碑版本 ( Ingalls M1)。稳定版本的目标是今年晚些时候。根据您的其他依赖项,您需要声明netty为附加依赖项,因为它目前在 Spring Data Cassandra 中被排除在外。

如何升级

Spring Boot 用户

将文件中的spring-data-releasetrain.version属性设置为并确保包含里程碑存储库声明:pom.xmlIngalls-M1

<properties>
    <spring-data-releasetrain.version>Ingalls-M1</spring-data-releasetrain.version>
</properties>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/libs-milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

Maven 用户(没有 Spring Boot 依赖管理)

将Spring Data Cassandra 包含1.5.0.M1在您的pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-cql</artifactId>
        <version>1.5.0.M1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-cassandra</artifactId>
        <version>1.5.0.M1</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/libs-milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

这是公告帖子的链接:https ://spring.io/blog/2016/07/27/spring-data-release-train-ingalls-m1-released

于 2016-08-16T15:26:59.067 回答