一个运行测试套件的项目 Spring-boot 2.2.6.RELEASE
以及 Spring-kafka 2.4.1.RELEASE
升级到时遇到问题 Spring-boot 2.3.1.RELEASE
以及 Spring-kafka 2.5.3.RELEASE
. 似乎找不到kafka.utils.testutils。
我试着将SpringKafka版本留空,以允许SpringBoot获取兼容的版本,但错误仍然存在。
build.gradle文件:
dependencies {
api "org.springframework.boot:spring-boot-starter-data-jpa:2.3.1.RELEASE"
api "org.springframework.boot:spring-boot-starter-web:2.3.1.RELEASE"
api "org.springframework.kafka:spring-kafka:2.5.3.RELEASE"
api "org.springframework.ws:spring-ws-core:3.0.9.RELEASE"
testImplementation "org.springframework.boot:spring-boot-starter-test:2.3.1.RELEASE"
testImplementation "org.springframework.kafka:spring-kafka-test:2.5.3.RELEASE"
}
我看到的错误是:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedKafka': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: kafka/utils/TestUtils
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:407)
at org.springframework.kafka.test.context.EmbeddedKafkaContextCustomizer.customizeContext(EmbeddedKafkaContextCustomizer.java:116)
at org.springframework.test.context.support.AbstractContextLoader.customizeContext(AbstractContextLoader.java:187)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:127)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:275)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
... 50 more
Caused by: java.lang.NoClassDefFoundError: kafka/utils/TestUtils
at org.springframework.kafka.test.EmbeddedKafkaBroker$EmbeddedZookeeper.<init>(EmbeddedKafkaBroker.java:655)
at org.springframework.kafka.test.EmbeddedKafkaBroker.afterPropertiesSet(EmbeddedKafkaBroker.java:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
... 59 more
Caused by: java.lang.ClassNotFoundException: kafka.utils.TestUtils
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
是否有一些明显的兼容性问题我遗漏了,或一些暂时的依赖,需要排除?
1条答案
按热度按时间jfewjypa1#
为了防止任何人遇到同样的问题,解决方法是从
spring-kafka
以及spring-kafka-test
为测试添加测试分类器: