spring kafka版本不兼容



我试图将kafka集成到项目中的一个服务中,但是它已经集成在另一个服务中,所以我自然地尝试使用使用这两个依赖项的相同kafka版本:

implementation 'org.springframework.integration:spring-integration-kafka:3.1.5.RELEASE'
implementation 'org.springframework.kafka:spring-kafka:2.2.15.RELEASE'

但是我得到的是这个错误:

Error creating bean with name 'kafkaProducerFactory' defined in class path resource [org/springframework/boot/autoconfigure/kafka/KafkaAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.kafka.core.ProducerFactory]: Factory method 'kafkaProducerFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/kafka/core/MicrometerProducerListener

得到之后,我查找了kafka spring兼容性矩阵(https://spring.io/projects/spring-kafka/#quick-start),并相应地更新了我的项目到

implementation 'org.springframework.kafka:spring-kafka:2.7.14'

服务工作,所以我尝试升级相同的依赖,但最终得到错误:

Error creating bean with name 'org.springframework.kafka.config.internalKafkaListenerAnnotationProcessor': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.kafka.annotation.KafkaListenerAnnotationBeanPostProcessor]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/log/LogAccessor

这对我来说真的很奇怪,因为两个服务上的spring版本是一样的,我知道我在这些服务上使用不同版本的kafka依赖,但是也许有人能给我一些清晰的问题,为什么会发生这种情况,为什么我不能只使用兼容性矩阵?(也许这只是一个错误的矩阵?)

第一个服务的Gradle构建文件:

plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.5.21'
id 'com.github.bjornvester.wsdl2java' version '1.2'
id 'org.springframework.boot' version '2.5.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'org.jetbrains.kotlin.plugin.lombok' version '1.5.21'
id 'io.freefair.lombok' version '5.3.0'
}
group = 'abc'
version = '1.5.3'
sourceCompatibility = '1.8'
wsdl2java {
wsdlDir = '../providers' as File
}
repositories {
mavenLocal()
mavenCentral()
}
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:2.1.7.RELEASE") {
bomProperty("kotlin.version", "1.4.30")
}
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Greenwich.SR3"
}
}
dependencies {
testCompile "junit:junit:4.11"
testCompile "org.springframework:spring-test:5.1.9.RELEASE"
implementation 'org.springframework:spring-context:5.1.9.RELEASE'
implementation 'commons-io:commons-io:2.4'
implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
compileOnly 'org.projectlombok:lombok:1.18.8'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'net.logstash.logback:logstash-logback-encoder:6.3'
implementation 'io.sentry:sentry-spring-boot-starter:5.4.0'
implementation 'io.sentry:sentry-logback:5.4.0'
implementation 'net.javacrumbs.shedlock:shedlock-spring:4.25.0'
implementation 'net.javacrumbs.shedlock:shedlock-provider-jdbc-template:4.25.0'
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
implementation "org.apache.httpcomponents:httpclient:4.5.+"
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final'
implementation 'org.mapstruct:mapstruct:1.4.2.Final'
implementation 'org.springframework:spring-web:5.1.9.RELEASE'
implementation 'org.springframework.ws:spring-ws-core:2.2.4.RELEASE'
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.springframework.boot:spring-boot-starter-web-services"
implementation "org.springframework.boot:spring-boot-starter-security"
implementation group: 'com.rabbitmq', name: 'amqp-client', version: '2.3.1'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.webjars:jquery:2.1.4'
implementation 'com.thoughtworks.xstream:xstream:1.4.7'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.9.9'
implementation 'com.hazelcast:hazelcast-spring:3.+'
implementation 'org.antlr:ST4:4.0.+'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.60'
implementation group: 'com.opencsv', name: 'opencsv', version: '5.2'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
implementation group: 'io.micrometer', name: 'micrometer-core'
implementation group: 'io.micrometer', name: 'micrometer-registry-prometheus'
implementation group: 'joda-time', name: 'joda-time', version: '2.3'
implementation 'com.vladmihalcea:hibernate-types-52:2.9.12'
implementation 'org.json:json:20090211'
implementation 'org.postgresql:postgresql:42.2.2'
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
implementation 'com.amazonaws:aws-java-sdk-s3:1.12.23'
implementation 'com.amazonaws:aws-java-sdk-core:1.12.23'
implementation 'org.springframework.integration:spring-integration-kafka:3.1.5.RELEASE'
implementation 'org.springframework.kafka:spring-kafka:2.2.15.RELEASE'
implementation 'com.ibm.mq:com.ibm.mq.allclient:9.2.2.0'
implementation 'org.springframework:spring-jms'
implementation "io.github.microutils:kotlin-logging-jvm:2.0.10"
annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final'
}

第二个:

plugins {
id 'org.springframework.boot' version '2.5.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'com.github.bjornvester.wsdl2java' version '1.2'
}
wsdl2java {
wsdlDir = '../providers' as File
generatedSourceDir = '../providers/ruru/build/generated/wsdl2java/sources/wsdl2java/java' as File
}
group = 'abc'
version = '1.1.13'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
maven {url 'https://maven.vaadin.com/vaadin-addons'}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework:spring-oxm:5.1.9.RELEASE'
implementation 'org.springframework.ws:spring-ws-core'
implementation 'org.springframework.ldap:spring-ldap-core:2.3.2.RELEASE'
implementation 'org.springframework.hateoas:spring-hateoas:1.4.0'
implementation 'com.vaadin:vaadin-spring-boot-starter:2.0.1'
implementation 'com.wcs.wcslib:wcslib-vaadin-widget-recaptcha:2.0.3'
implementation 'com.thoughtworks.xstream:xstream:1.4.7'
implementation 'org.postgresql:postgresql:42.2.2'
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.vladmihalcea:hibernate-types-52:2.9.12'
implementation 'com.vaadin:vaadin-compatibility-server:8.14.3'
implementation 'com.vaadin:vaadin-client-compiled:8.14.3'
implementation 'com.vaadin:vaadin-compatibility-client-compiled:8.14.3'
implementation 'com.vaadin:vaadin-compatibility-themes:8.14.3'
implementation 'com.vaadin:vaadin-themes:8.14.3'
implementation 'com.vaadin.addon:jpacontainer:4.0.0'
implementation 'org.apache.httpcomponents:httpclient:4.5.+'
implementation 'org.apache.commons:commons-csv:1.5'
implementation 'dev.samstevens.totp:totp:1.6.1'
implementation 'commons-io:commons-io:2.4'
implementation 'org.json:json:20090211'
implementation 'org.apache.tika:tika-core:1.+'
implementation("io.sentry:sentry-spring-boot-starter:5.4.0")
implementation("io.sentry:sentry-logback:5.4.0")
implementation 'commons-beanutils:commons-beanutils:1.9.4'
implementation 'org.apache.commons:commons-collections4:4.4'
implementation 'io.micrometer:micrometer-core'
implementation 'com.opencsv:opencsv:5.2'
implementation 'org.springframework.integration:spring-integration-kafka:3.1.5.RELEASE'
implementation 'org.springframework.kafka:spring-kafka:2.7.14'

runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
compileOnly 'org.projectlombok:lombok:1.18.8'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}

您的Spring Framework版本(5.1.9.RELEASE)太旧;一般来说,最好只指定Boot版本,它会使用它的依赖管理功能引入所有依赖的正确版本。

同样,spring-integration-kafka必须是5.5。X(根据该矩阵)

相关内容

  • 没有找到相关文章