【问题标题】:'cassandraCluster' bean exception while starting Spring Boot Application启动 Spring Boot 应用程序时出现“cassandraCluster”bean 异常
【发布时间】:2020-06-24 19:48:38
【问题描述】:

我在启动 Spring Boot 应用程序时遇到以下异常。 Spring Boot 版本:2.1.13 Spring 框架版本:5.1.14

例外: org.springframework.beans.factory.BeanCreationException:在类路径资源[org/springframework/boot/autoconfigure/cassandra/Cas​​sandraAutoConfiguration.class]中定义名称为“cassandraCluster”的bean创建错误:通过工厂方法进行的bean实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [com.datastax.driver.core.Cluster]:工厂方法“cassandraCluster”抛出异常;嵌套异常是 java.lang.ExceptionInInitializerError 在 org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE] 在 org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1320) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1159) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE] 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE] 在 org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:847) ~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.14.RELEASE.jar:5.1.14.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.14.RELEASE.jar:5.1.14.RELEASE] 在 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE] 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) ~[spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE] 在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) ~[spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE] 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-2.1.13.RELEASE.jar:2.1.13.RELEASE]

原因: 原因:com.datastax.driver.core.exceptions.DriverInternalError:在类路径中检测到不兼容的 Guava 版本。您需要 16.0.1 或更高版本。 在 com.datastax.driver.core.GuavaCompatibility.selectImplementation(GuavaCompatibility.java:191) ~[cassandra-driver-core-3.6.0.jar:na] 在 com.datastax.driver.core.GuavaCompatibility.(GuavaCompatibility.java:59) ~[cassandra-driver-core-3.6.0.jar:na] ...省略了30个常用框架

但我在类路径中有 guava-19.0 版本的 jar。

我在使用 Spring Boot 2.1.6 和 Spring Framework 5.1.5 时没有遇到这个问题。

【问题讨论】:

    标签: spring spring-boot cassandra guava


    【解决方案1】:

    您的类路径中似乎有两个版本的 Guava。其他一些软件包可能会拉取其他版本。您应该将 Guava 的版本固定在 Maven 的 <dependencyManagement> 部分中(我希望您使用 Maven):

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>com.google.guava</groupId>
          <artifactId>guava</artifactId>
          <version>19.0</version>
        </dependency>
     </dependencies>
    </dependencyManagement>
    

    或者从另一个拉取它的依赖中排除 Guava 依赖。

    未来提示:考虑将 Maven Enforcer Plugin 添加到您的项目中并检查依赖收敛以检查此类类似问题:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>1.4.1</version>
                <executions>
                    <execution>
                        <id>enforce</id>
                        <configuration>
                            <rules>
                                <DependencyConvergence/>
                            </rules>
                        </configuration>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <phase>validate</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    ...
    </build>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-26
      • 2015-06-09
      • 2015-03-14
      • 2018-03-05
      • 1970-01-01
      • 2023-02-01
      相关资源
      最近更新 更多