java @GrpcClient为空 Spring Boot 3

iugsix8n  于 2023-03-11  发布在  Java
关注(0)|答案(1)|浏览(299)

我正在使用net.devh.grpc-client-spring-boot-starter制作grpc客户端
委托单位:

@Service
public class SystemService {
    @GrpcClient("handyman-client")
    StatusServiceGrpc.StatusServiceBlockingStub handymanClient;

    public VersionResponse getHandymanVersion() {
        return handymanClient.getVersion(Empty.newBuilder().build());
    }
}

application.yaml:

grpc:
  client:
    handyman-client:
      address: static://localhost:8080
      negotiationType: plaintext

在运行时,handymanClientnull。尝试了从3.0.03.0.2的 Spring Boot 版本。将Spring引导版本降低到2.7.0解决了问题-现在正在创建客户端。
是否有变通方案使其在 Spring Boot 3上工作?
build.gradle:

plugins {
id 'java'
id 'org.springframework.boot' version '3.0.0'
id 'io.spring.dependency-management' version '1.1.0'
id "com.google.protobuf" version "0.9.2"
}

group = 'hello.grpc'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

configurations {
compileOnly {
    extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'javax.annotation:javax.annotation-api:1.3.2'

implementation group: 'net.devh', name: 'grpc-client-spring-boot-starter', version: '2.13.0.RELEASE'
implementation group: 'io.grpc', name: 'grpc-stub', version: '1.53.0'
implementation group: 'io.grpc', name: 'grpc-protobuf', version: '1.53.0'

}

sourceSets {
main {
    java {
        srcDirs 'build/generated/source/proto/main/grpc'
        srcDirs 'build/generated/source/proto/main/java'
    }
}
}

protobuf {
protoc {
    artifact = 'com.google.protobuf:protoc:4.0.0-rc-2'
}
plugins {
    grpc {
        artifact = 'io.grpc:protoc-gen-grpc-java:1.53.0'
    }
}
generateProtoTasks {
    all()*.plugins {
        grpc {}
    }
}
}

tasks.named('test') {
useJUnitPlatform()
}

springBoot {
buildInfo()
}
pqwbnv8z

pqwbnv8z1#

由于springboot 3中的自动配置发生了变化,因此META-INF/spring.factories被更新为META-INF/spring/org. springframework. boot. autoconfigure. AutoConfiguration. imports。该更新阻止了grpc-client自动安装。在最新的master分支上,增加了springboot 3的自动汇编。您可以下载源代码并编译安装它。
source code

相关问题