grpc-spring-boot-starter - 如果我将 spring-boot-starter-jdbc 添加到依赖项中,netty 服务器不会启动

问题描述 投票:0回答:1

我开始用 spring boot 测试 grpc,我使用 net.devh:grpc-spring-boot-starter 中提供的 GrpcService (https://yidongnan.github.io/grpc-spring-boot-starter /zh/)。

它独立工作得很好,就像,如果我将它添加到一个项目并构建一个 GrpcService,netty 启动正常并且服务可用。我的 gradle.build

import com.google.protobuf.gradle.*

plugins {
    id("org.springframework.boot") version "3.1.2"
    id( "com.google.protobuf") version "0.8.18"
    kotlin("jvm") version "1.9.0"
}

group = "org.example"
version = "1.0-SNAPSHOT"

val isLocal: String? by project

repositories {

... my repos
    }
}

dependencies {
    implementation("net.devh:grpc-spring-boot-starter:2.14.0.RELEASE")
    testImplementation(kotlin("test"))
}

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.23.4"
    }

    generatedFilesBaseDir = "${project.projectDir.absolutePath}/src/generated"

    plugins {
        id("grpc") {
            artifact = "io.grpc:protoc-gen-grpc-java:1.58.0"
        }
    }

    generateProtoTasks {
        ofSourceSet("main").forEach {
            it.plugins {
                id("grpc") {}
            }
        }
    }
}
2024-01-18 07:42:26.245  INFO 15644 --- [           main] org.example.ApplicationKt                : No active profile set, falling back to 1 default profile: "default"
2024-01-18 07:42:27.385  INFO 15644 --- [           main] n.d.b.g.c.a.GrpcClientAutoConfiguration  : Detected grpc-netty-shaded: Creating ShadedNettyChannelFactory + InProcessChannelFactory
2024-01-18 07:42:28.010  INFO 15644 --- [           main] g.s.a.GrpcServerFactoryAutoConfiguration : Detected grpc-netty-shaded: Creating ShadedNettyGrpcServerFactory
2024-01-18 07:42:28.086  INFO 15644 --- [           main] g.s.a.GrpcServerFactoryAutoConfiguration : 'grpc.server.in-process-name' is set: Creating InProcessGrpcServerFactory
2024-01-18 07:42:28.279  INFO 15644 --- [           main] n.d.b.g.s.s.AbstractGrpcServerFactory    : Registered gRPC service: grpc.tests.PingService, bean: pingService, class: org.example.PingService
2024-01-18 07:42:28.279  INFO 15644 --- [           main] n.d.b.g.s.s.AbstractGrpcServerFactory    : Registered gRPC service: grpc.health.v1.Health, bean: grpcHealthService, class: io.grpc.protobuf.services.HealthServiceImpl
2024-01-18 07:42:28.279  INFO 15644 --- [           main] n.d.b.g.s.s.AbstractGrpcServerFactory    : Registered gRPC service: grpc.reflection.v1alpha.ServerReflection, bean: protoReflectionService, class: io.grpc.protobuf.services.ProtoReflectionService
2024-01-18 07:42:28.465  INFO 15644 --- [           main] n.d.b.g.s.s.GrpcServerLifecycle          : gRPC Server started, listening on address: *, port: 9090
2024-01-18 07:42:28.470  INFO 15644 --- [           main] n.d.b.g.s.s.AbstractGrpcServerFactory    : Registered gRPC service: grpc.tests.PingService, bean: pingService, class: org.example.PingService
2024-01-18 07:42:28.471  INFO 15644 --- [           main] n.d.b.g.s.s.AbstractGrpcServerFactory    : Registered gRPC service: grpc.health.v1.Health, bean: grpcHealthService, class: io.grpc.protobuf.services.HealthServiceImpl
2024-01-18 07:42:28.471  INFO 15644 --- [           main] n.d.b.g.s.s.AbstractGrpcServerFactory    : Registered gRPC service: grpc.reflection.v1alpha.ServerReflection, bean: protoReflectionService, class: io.grpc.protobuf.services.ProtoReflectionService
2024-01-18 07:42:28.474  INFO 15644 --- [           main] n.d.b.g.s.s.GrpcServerLifecycle          : gRPC Server started, listening on address: in-process:test, port: -1
2024-01-18 07:42:28.493  INFO 15644 --- [           main] org.example.ApplicationKt                : Started ApplicationKt in 3.012 seconds (JVM running for 3.829)

但是,如果我更改依赖项并添加 spring-boot-starter-jdbc,GrpcService 不会启动,就像 Netty 没有启动一样:

dependencies {
    implementation("net.devh:grpc-spring-boot-starter:2.14.0.RELEASE")
    implementation("org.springframework.boot:spring-boot-starter-jdbc:3.1.5")
    implementation("com.microsoft.sqlserver:mssql-jdbc:7.4.1.jre8")
    implementation("javax.annotation:javax.annotation-api:1.3.2")
    testImplementation(kotlin("test"))
}
2024-01-18T07:46:09.797-05:00  INFO 19892 --- [           main] org.example.ApplicationKt                : Starting ApplicationKt using Java 17.0.8 with PID 19892
2024-01-18T07:46:09.804-05:00  INFO 19892 --- [           main] org.example.ApplicationKt                : No active profile set, falling back to 1 default profile: "default"
2024-01-18T07:46:11.339-05:00  INFO 19892 --- [           main] org.example.ApplicationKt                : Started ApplicationKt in 2.223 seconds (process running for 3.064)

我已经尝试将 grpc-server-spring-boot-autoconfigure 添加到依赖项中,但仍然存在同样的问题。

有人遇到过类似的问题吗?

谢谢!

spring-boot grpc
1个回答
0
投票

谢谢M.Deinum。

一旦我将插件和依赖项移至 3.2.1,并将 grpc-spring-boot-starter 移至 2.15.0。发布一切似乎都工作正常。

© www.soinside.com 2019 - 2024. All rights reserved.