spring-data-cassandra-2.0.0.RELEASE + spring-boot-starter-web-1.5.7.RELEASE导致java.lang.ClassNotFoundException

时间:2017-10-16 18:42:25

标签: spring-data-cassandra spring-boot-starter

我使用最新版本的spring-data-cassandra,它是2.0.0.RELEASE和最新版本的spring-boot-starter-web - 1.5.7.RELEASE

Resources:
  DnsRedis:
    Type: 'AWS::Route53::RecordSetGroup'
    Properties:
      HostedZoneName: 'a.hosted.zone.name.'
      RecordSets:
        - Name: 'a.record.set.name'
          Type: CNAME
          TTL: '300'
          ResourceRecords:
            - !GetAtt
              - RedisCacheCluster
              - RedisEndpoint.Address  
    DependsOn: RedisCacheCluster

  RedisCacheCluster:
    Type: 'AWS::ElastiCache::CacheCluster'
    Properties:
      ClusterName: cluster-name-redis
      AutoMinorVersionUpgrade: 'true'
      AZMode: single-az
      CacheNodeType: cache.t2.small
      Engine: redis
      EngineVersion: 3.2.4
      NumCacheNodes: 1
      CacheSubnetGroupName: !Ref ElastiCacheSubnetGroupId
      VpcSecurityGroupIds:
        - !GetAtt
          - elasticacheSecGrp
          - GroupId

我可以毫无问题地构建项目,但是应用程序不会以以下异常开始:

  <dependencies>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-cassandra</artifactId>
        <version>2.0.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>1.5.7.RELEASE</version>
    </dependency>
</dependencies>

根本原因:

java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration.cassandraMapping
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:64) ~[spring-boot-autoconfigure-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:109) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:179) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:141) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:117) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:328) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:271) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:693) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at Application.main(Application.java:8) [classes/:na]

看起来问题出在spring-boot-autoconfigure-1.5.7.RELEASE中,如果我将spring-boot-starter-web更新为2.0.0.M5:

Caused by: java.lang.ClassNotFoundException: org.springframework.data.cassandra.mapping.CassandraMappingContext
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_144]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_144]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_144]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_144]
at org.springframework.util.ClassUtils.forName(ClassUtils.java:255) ~[spring-core-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.boot.autoconfigure.condition.OnBeanCondition$BeanSearchSpec.addDeducedBeanTypeForBeanMethod(OnBeanCondition.java:356) ~[spring-boot-autoconfigure-1.5.7.RELEASE.jar:1.5.7.RELEASE]
... 21 common frames omitted

然后应用程序启动没有任何错误。

有没有办法使用spring-data-cassandra的最新版本以及spring-boot-starter-web,还是应该等待spring-boot-starter-web的GA:2.0.0?

提前谢谢!

2 个答案:

答案 0 :(得分:0)

最新版本的Spring Data Cassandra是2.0.0,它与Spring Boot 1.x不兼容。您需要将依赖项升级到Spring Boot 2.0 M5。

答案 1 :(得分:0)

嗨,我遇到了同样的问题,所以在这里我做了什么, 首先,我在cassandra中连接多个键空间,并使用带有 Spring Boot Starter 2.0.0。发布 我删除了spring数据cassandra的版本声明,但是其托管版本为2.0.5.RELEASE,因此您可以进行检查。 第二我在org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration时出错 是在2.0.0.RELEASE之前和之内导入的,已移至 org.springframework.data.cassandra.config.AbstractCassandraConfiguration 所以一定要检查一下