我尝试在Cassandra 2.1.12 (作为DSE 4.8.4的一部分)上使用Spring-data-cassandra 1.3.4和最新的cassandra-driver-core : 3.0.0,一切正常。同样的spring batch在普通的Cassandra 3.x版本中不起作用。我在Cassandra 3.2、3.3和3.4上试用了一下。
我得到了下面堆栈跟踪中提到的ClassNotFound Exception。
现在我完全理解了这是因为"com.datastax.driver.core.DataType.java“中没有出现一个特定的方法(AsJavaClass)。
我的问题是,有没有其他方法可以绕过这一点?
我正在使用Spring批处理来进行一次性数据加载,这是非常庞大的。而且我不能使用低于Cassandra 3.3的任何东西。
2016-04-11 13:38:32.684 WARN 3166 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingContext' defined in class path resource [com/walgreens/batch/config/CassandraConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.mapping.CassandraMappingContext]: Factory method 'mappingContext' threw exception; nested exception is java.lang.NoSuchMethodError: com.datastax.driver.core.DataType.asJavaClass()Ljava/lang/Class;
2016-04-11 13:38:32.808 ERROR 3166 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingContext' defined in class path resource [com/walgreens/batch/config/CassandraConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.mapping.CassandraMappingContext]: Factory method 'mappingContext' threw exception; nested exception is java.lang.NoSuchMethodError: com.datastax.driver.core.DataType.asJavaClass()Ljava/lang/Class;
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at com.walgreens.batch.WagStoreInventoryBatchJobApplication.main(WagStoreInventoryBatchJobApplication.java:43) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.mapping.CassandraMappingContext]: Factory method 'mappingContext' threw exception; nested exception is java.lang.NoSuchMethodError: com.datastax.driver.core.DataType.asJavaClass()Ljava/lang/Class;
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 17 common frames omitted
Caused by: java.lang.NoSuchMethodError: com.datastax.driver.core.DataType.asJavaClass()Ljava/lang/Class;
at org.springframework.data.cassandra.mapping.CassandraSimpleTypeHolder.<clinit>(CassandraSimpleTypeHolder.java:62) ~[spring-data-cassandra-1.3.4.RELEASE.jar:na]
at org.springframework.data.cassandra.mapping.BasicCassandraMappingContext.<init>(BasicCassandraMappingContext.java:73) ~[spring-data-cassandra-1.3.4.RELEASE.jar:na]
at com.walgreens.batch.config.CassandraConfiguration.mappingContext(CassandraConfiguration.java:47) ~[classes/:na]
at com.walgreens.batch.config.CassandraConfiguration$$EnhancerBySpringCGLIB$$78a36265.CGLIB$mappingContext$4(<generated>) ~[classes/:na]
at com.walgreens.batch.config.CassandraConfiguration$$EnhancerBySpringCGLIB$$78a36265$$FastClassBySpringCGLIB$$c7f2ad2a.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:355) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at com.walgreens.batch.config.CassandraConfiguration$$EnhancerBySpringCGLIB$$78a36265.mappingContext(<generated>) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_60]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_60]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 18 common frames omitted
/*
* 提示:该行代码过长,系统自动注释不进行高亮。一键复制会移除系统注释
* 2016-04-11 13:38:32.811 INFO 3166 --- [ main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/Users/Siraj/Documents/workspace/Ask2/WagStoreInventoryBatchJob/target/classes/, file:/Users/Siraj/.m2/repository/org/springframework/boot/spring-boot-starter-batch/1.3.3.RELEASE/spring-boot-starter-batch-1.3.3.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/boot/spring-boot-starter/1.3.3.RELEASE/spring-boot-starter-1.3.3.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/boot/spring-boot/1.3.3.RELEASE/spring-boot-1.3.3.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.3.3.RELEASE/spring-boot-autoconfigure-1.3.3.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.3.3.RELEASE/spring-boot-starter-logging-1.3.3.RELEASE.jar, file:/Users/Siraj/.m2/repository/ch/qos/logback/logback-classic/1.1.5/logback-classic-1.1.5.jar, file:/Users/Siraj/.m2/repository/ch/qos/logback/logback-core/1.1.5/logback-core-1.1.5.jar, file:/Users/Siraj/.m2/repository/org/slf4j/jul-to-slf4j/1.7.16/jul-to-slf4j-1.7.16.jar, file:/Users/Siraj/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.16/log4j-over-slf4j-1.7.16.jar, file:/Users/Siraj/.m2/repository/org/yaml/snakeyaml/1.16/snakeyaml-1.16.jar, file:/Users/Siraj/.m2/repository/org/hsqldb/hsqldb/2.3.3/hsqldb-2.3.3.jar, file:/Users/Siraj/.m2/repository/org/springframework/spring-jdbc/4.2.5.RELEASE/spring-jdbc-4.2.5.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/spring-beans/4.2.5.RELEASE/spring-beans-4.2.5.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/batch/spring-batch-core/3.0.6.RELEASE/spring-batch-core-3.0.6.RELEASE.jar, file:/Users/Siraj/.m2/repository/com/ibm/jbatch/com.ibm.jbatch-tck-spi/1.0/com.ibm.jbatch-tck-spi-1.0.jar, file:/Users/Siraj/.m2/repository/javax/batch/javax.batch-api/1.0/javax.batch-api-1.0.jar, file:/Users/Siraj/.m2/repository/com/thoughtworks/xstream/xstream/1.4.7/xstream-1.4.7.jar, file:/Users/Siraj/.m2/repository/xmlpull/xmlpull/1.1.3.1/xmlpull-1.1.3.1.jar, file:/Users/Siraj/.m2/repository/xpp3/xpp3_min/1.1.4c/xpp3_min-1.1.4c.jar, file:/Users/Siraj/.m2/repository/org/codehaus/jettison/jettison/1.2/jettison-1.2.jar, file:/Users/Siraj/.m2/repository/org/springframework/batch/spring-batch-infrastructure/3.0.6.RELEASE/spring-batch-infrastructure-3.0.6.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/retry/spring-retry/1.1.2.RELEASE/spring-retry-1.1.2.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/spring-context/4.2.5.RELEASE/spring-context-4.2.5.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/boot/spring-boot-starter-data-cassandra/1.3.3.RELEASE/spring-boot-starter-data-cassandra-1.3.3.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/spring-tx/4.2.5.RELEASE/spring-tx-4.2.5.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/data/spring-data-cassandra/1.3.4.RELEASE/spring-data-cassandra-1.3.4.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/data/spring-cql/1.3.4.RELEASE/spring-cql-1.3.4.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/spring-expression/4.2.5.RELEASE/spring-expression-4.2.5.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/data/spring-data-commons/1.11.4.RELEASE/spring-data-commons-1.11.4.RELEASE.jar, file:/Users/Siraj/.m2/repository/com/datastax/cassandra/cassandra-driver-dse/2.1.9/cassandra-driver-dse-2.1.9.jar, file:/Users/Siraj/.m2/repository/org/slf4j/slf4j-api/1.7.16/slf4j-api-1.7.16.jar, file:/Users/Siraj/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.16/jcl-over-slf4j-1.7.16.jar, file:/Users/Siraj/.m2/repository/org/springframework/boot/spring-boot-starter-jdbc/1.3.3.RELEASE/spring-boot-starter-jdbc-1.3.3.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/apache/tomcat/tomcat-jdbc/8.0.32/tomcat-jdbc-8.0.32.jar, file:/Users/Siraj/.m2/repository/org/apache/tomcat/tomcat-juli/8.0.32/tomcat-juli-8.0.32.jar, file:/Users/Siraj/.m2/repository/com/datastax/cassandra/cassandra-driver-core/3.0.0/cassandra-driver-core-3.0.0.jar, file:/Users/Siraj/.m2/repository/io/netty/netty-handler/4.0.33.Final/netty-handler-4.0.33.Final.jar, file:/Users/Siraj/.m2/repository/io/netty/netty-buffer/4.0.33.Final/netty-buffer-4.0.33.Final.jar, file:/Users/Siraj/.m2/repository/io/netty/netty-common/4.0.33.Final/netty-common-4.0.33.Final.jar, file:/Users/Siraj/.m2/repository/io/netty/netty-transport/4.0.33.Final/netty-transport-4.0.33.Final.jar, file:/Users/Siraj/.m2/repository/io/netty/netty-codec/4.0.33.Final/netty-codec-4.0.33.Final.jar, file:/Users/Siraj/.m2/repository/com/google/guava/guava/16.0.1/guava-16.0.1.jar, file:/Users/Siraj/.m2/repository/io/dropwizard/metrics/metrics-core/3.1.2/metrics-core-3.1.2.jar, file:/Users/Siraj/.m2/repository/joda-time/joda-time/2.8.2/joda-time-2.8.2.jar, file:/Users/Siraj/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar, file:/Users/Siraj/.m2/repository/org/springframework/boot/spring-boot-configuration-processor/1.3.3.RELEASE/spring-boot-configuration-processor-1.3.3.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/json/json/20140107/json-20140107.jar, file:/Users/Siraj/.m2/repository/org/springframework/spring-core/4.2.5.RELEASE/spring-core-4.2.5.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/boot/spring-boot-starter-aop/1.3.3.RELEASE/spring-boot-starter-aop-1.3.3.RELEASE.jar, file:/Users/Siraj/.m2/repository/org/springframework/spring-aop/4.2.5.RELEASE/spring-aop-4.2.5.RELEASE.jar, file:/Users/Siraj/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar, file:/Users/Siraj/.m2/repository/org/aspectj/aspectjweaver/1.8.8/aspectjweaver-1.8.8.jar, file:/Users/Siraj/.m2/repository/com/oracle/ojdbc6/11.2.0.4/ojdbc6-11.2.0.4.jar]
*/发布于 2016-04-12 05:27:15
Spring-Data-Cassandra1.3.4(甚至是最新的开发版本)使用客户端驱动程序Cassandra 2.1.x请参阅Datastax驱动程序compatibility chart,您将看到需要3.x客户端驱动程序才能使用Cassandra3.x。
正如Aaron提到的,它不是C*的最好的对象关系管理实现,因为它最初是为关系型数据库接口设计的,因此它的实现是NoSQL数据库的反模式。
你提到这是一个一次性的批量数据加载,我首先要了解一下将大量数据加载到Cassandra from this article中的最佳方法(提示不要使用批处理)。我不知道有什么真正好的工具可以做一些开箱即用的数据迁移(取决于你的源系统是什么)。所以你可能不得不写一些定制的东西,或者改写一些东西。
发布于 2016-04-12 04:21:22
不幸的是,当您选择使用框架驱动程序而不是approved DataStax Driver时,这是您要承担的风险之一。
如果您想要使用尖端版本的Cassandra,那么为了确保您部署成功的应用程序的机会最高,您还应该使用DataStax Java驱动程序(在您的例子中)。
此外,还有另外两个原因让你重新考虑使用spring-cassandra-data:
spring当您调用insert(List<T> entities, WriteOptions options) (和相关方法)时,-
COUNT(*)。在有许多节点的集群上运行这是一个非常低效的查询。在较大的表上,它将很慢,并且可能会超时。正如我经常说的,选择DataStax认可的驱动程序是不会出错的。
发布于 2016-04-12 04:12:40
2016嵌套异常为com.datastax.driver.core.DataType.asJavaClass()Ljava/lang/Class;:
java.lang.NoSuchMethodError-04-11 13:38:32.808
可能Spring Batch使用的Java驱动程序版本没有使用最新版本(3.0.0)
https://stackoverflow.com/questions/36558099
复制相似问题