You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加spring-boot-starter-jdbc后Grpc Netty Server无法启动求助

Spring Boot集成gRPC添加JDBC依赖后Netty无法启动问题

我正在使用net.devh:grpc-spring-boot-starter的GrpcService测试Spring Boot集成gRPC。单独运行时Netty启动正常,gRPC服务可正常访问,但添加spring-boot-starter-jdbc等依赖后,gRPC服务无法启动,Netty未正常初始化。


一、正常运行时的配置与日志

Gradle配置

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 {
    // 自定义仓库
}

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)

二、添加JDBC依赖后的异常情况

修改后的Gradle依赖

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依赖,问题未解决。

求解决方案。


内容的提问来源于stack exchange,提问作者Francisco Cerqueira

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 07:20:55