';cassandraCluster';启动Spring启动应用程序时出现bean异常

';cassandraCluster';启动Spring启动应用程序时出现bean异常,spring,spring-boot,cassandra,guava,Spring,Spring Boot,Cassandra,Guava,我在启动Spring启动应用程序时遇到以下异常。 Spring启动版本:2.1.13 Spring框架版本:5.1.14 例外情况: org.springframework.beans.factory.BeanCreationException:创建名为“cassandraCluster”的bean时出错,该bean在类路径资源[org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.class]:通

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

例外情况: org.springframework.beans.factory.BeanCreationException:创建名为“cassandraCluster”的bean时出错,该bean在类路径资源[org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.class]:通过工厂方法实例化bean失败;嵌套异常为org.springframework.beans.BeanInstantiationException:未能实例化[com.datasax.driver.core.Cluster]:工厂方法“cassandraCluster”引发异常;嵌套异常为java.lang.ExceptionInInitializeError 在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.InstanceUsingFactoryMethod(ConstructorResolver.java:456)~[spring-beans-5.1.14.RELEASE.jar:5.1.14.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.InstanceUsingFactoryMethod(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.PreInstanceSingleton(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.driverPrinternalError:在类路径中检测到不兼容的Guava版本。您需要16.0.1或更高版本。 在com.datasax.driver.core.GuavaCompatibility.selectImplementation(GuavaCompatibility.java:191)~[cassandra-driver-core-3.6.0.jar:na] 在com.datasax.driver.core.GuavaCompatibility.(GuavaCompatibility.java:59)~[cassandra-driver-core-3.6.0.jar:na] ... 省略30个公共框架

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


我在SpringBoot2.1.6和SpringFramework 5.1.5中没有遇到这个问题。

看起来类路径上有两个版本的Guava。其他一些包可能会拉其他版本。您应该在Maven的
部分中固定番石榴的版本(我希望您使用Maven):


番石榴
番石榴
19
或者将番石榴的依赖性从另一个同样吸引它的依赖性中排除

未来的提示:考虑将Maven执行器插件添加到项目中,检查依赖性收敛以检查类似的问题:

<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>

org.apache.maven.plugins
maven enforcer插件
1.4.1
执行
执行
验证
...
<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>