Spring Boot 1.4:Spring Data Cassandra 1.4.2 与 Cassandra 3.0 不兼容?
Posted
技术标签:
【中文标题】Spring Boot 1.4:Spring Data Cassandra 1.4.2 与 Cassandra 3.0 不兼容?【英文标题】:Spring Boot 1.4: Spring Data Cassandra 1.4.2 is incompatible with Cassandra 3.0? 【发布时间】:2016-12-23 00:58:32 【问题描述】:当我尝试在大多数版本的 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
【问题讨论】:
@mp911de 你应该发表你的评论作为答案。这很有帮助,你甚至在 Pivotal 工作 @mp911de 我应该怎么做才能玩它? 你说得对,带有 Spring Data Cassandra 1.4.2 的 Spring Boot 1.4 与 Cassandra 3.0 不兼容。 Spring Data 1.5(将)与 Cassandra 3.0 兼容。我们已经发布了一个里程碑版本。 【参考方案1】:你说得对,带有 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 用户
将pom.xml
文件中的spring-data-releasetrain.version
属性设置为Ingalls-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 依赖管理)
在您的pom.xml
中包含 Spring Data Cassandra 1.5.0.M1
:
<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
【讨论】:
我的“pom.xml”中没有“spring-data-releasetrain.version”,我应该添加它,如果是的话,如何添加?请。我这样做:<cassandra-driver.version>3.0.3</cassandra-driver.version>
覆盖版本。
cassandra-driver-mapping
未被 Spring Data Cassandra 使用。驱动程序具有正确的版本号,但我从堆栈跟踪中看到 Spring Data Cassandra 仍然是 1.4.x 而不是 1.5.0.M1。以上是关于Spring Boot 1.4:Spring Data Cassandra 1.4.2 与 Cassandra 3.0 不兼容?的主要内容,如果未能解决你的问题,请参考以下文章
在 Spring Boot 1.4 中测试 Spring MVC 切片的问题
spring cloud 版本 Brixton.SR5 with spring boot 1.4
Spring boot 1.4 测试:配置错误:发现@BootstrapWith 的多个声明
Spring Data + Hibernate 5 (Spring Boot 1.4) - 获取弃用消息
Spring Boot 1.4:Spring Data Cassandra 1.4.2 与 Cassandra 3.0 不兼容?