{"id":15196911,"url":"https://github.com/grpc-ecosystem/grpc-spring","last_synced_at":"2025-05-13T19:09:30.547Z","repository":{"id":37549718,"uuid":"77675033","full_name":"grpc-ecosystem/grpc-spring","owner":"grpc-ecosystem","description":"Spring Boot starter module for gRPC framework.","archived":false,"fork":false,"pushed_at":"2025-04-25T13:30:21.000Z","size":3936,"stargazers_count":3611,"open_issues_count":163,"forks_count":851,"subscribers_count":118,"default_branch":"master","last_synced_at":"2025-04-27T05:46:33.985Z","etag":null,"topics":["grpc","grpc-framework","grpc-java","java","spring","spring-boot","spring-boot-grpc","spring-boot-starter","spring-cloud"],"latest_commit_sha":null,"homepage":"https://grpc-ecosystem.github.io/grpc-spring/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grpc-ecosystem.png","metadata":{"files":{"readme":"README-zh-CN.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-12-30T09:06:15.000Z","updated_at":"2025-04-25T10:19:20.000Z","dependencies_parsed_at":"2023-02-19T02:01:17.585Z","dependency_job_id":"9d256441-46cf-44cc-aa10-0fb85b997f03","html_url":"https://github.com/grpc-ecosystem/grpc-spring","commit_stats":{"total_commits":1074,"total_committers":79,"mean_commits":"13.594936708860759","dds":0.7420856610800746,"last_synced_commit":"a18aeeb25e60114ea773a621bfdc44902513ed07"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grpc-ecosystem%2Fgrpc-spring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grpc-ecosystem%2Fgrpc-spring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grpc-ecosystem%2Fgrpc-spring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grpc-ecosystem%2Fgrpc-spring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grpc-ecosystem","download_url":"https://codeload.github.com/grpc-ecosystem/grpc-spring/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251094601,"owners_count":21535325,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grpc","grpc-framework","grpc-java","java","spring","spring-boot","spring-boot-grpc","spring-boot-starter","spring-cloud"],"created_at":"2024-09-28T00:20:32.056Z","updated_at":"2025-04-27T05:46:38.670Z","avatar_url":"https://github.com/grpc-ecosystem.png","language":"Java","readme":"# gRPC Spring Boot Starter\n\n[![Build master branch](https://github.com/grpc-ecosystem/grpc-spring/workflows/Build%20master%20branch/badge.svg)](https://github.com/grpc-ecosystem/grpc-spring/actions) [![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/net.devh/grpc-spring-boot-starter.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22net.devh%22%20grpc) [![License](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE) [![Crowdin](https://badges.crowdin.net/grpc-spring-boot-starter/localized.svg)](https://crowdin.com/project/grpc-spring-boot-starter)\n\n[![Client-Javadoc](https://www.javadoc.io/badge/net.devh/grpc-client-spring-boot-starter.svg?label=Client-Javadoc)](https://www.javadoc.io/doc/net.devh/grpc-client-spring-boot-starter) [![Server-Javadoc](https://www.javadoc.io/badge/net.devh/grpc-server-spring-boot-starter.svg?label=Server-Javadoc)](https://www.javadoc.io/doc/net.devh/grpc-server-spring-boot-starter) [![Common-Javadoc](https://www.javadoc.io/badge/net.devh/grpc-common-spring-boot.svg?label=Common-Javadoc)](https://www.javadoc.io/doc/net.devh/grpc-common-spring-boot)\n\nREADME: [English](README.md) | [中文](README-zh-CN.md)\n\n**文档：** [English](https://yidongnan.github.io/grpc-spring-boot-starter/en/) | [中文](https://yidongnan.github.io/grpc-spring-boot-starter/zh-CN/)\n\n## 特性\n\n* 使用 `@GrpcService` 注解可以实现自动配置和运行 gRPC Server 端\n\n* 使用 `@GrpcClient` 注解可以实现自动创建和管理您的 gRPC Channels 和 stubs\n\n* 支持其他 grpc-java 的变种 (例如： [Reactive gRPC (RxJava)](https://github.com/salesforce/reactive-grpc/tree/master/rx-java), [grpc-kotlin](https://github.com/grpc/grpc-kotlin), ...)\n  * Server 端：适用于所有 grpc-java 的变种 ( 基于 `io.grpc.BindableService`)\n  * Client 端：需要自定义 `StubFactory` 当前内置支持：\n    * grpc-java\n    * (请告知我们不支持的组件，我们可以添加对它们的支持)\n\n* 支持 [Spring-Security](https://github.com/spring-projects/spring-security)\n\n* 支持 [Spring Cloud](https://spring.io/projects/spring-cloud)\n  * 服务端：向服务注册详情中添加 gRPC 端口信息。 目前原生支持：\n    * [Consul](https://github.com/spring-cloud/spring-cloud-consul)\n    * [Eureka](https://github.com/spring-cloud/spring-cloud-netflix)\n    * [Nacos](https://github.com/spring-cloud-incubator/spring-cloud-alibaba)\n    * (请告诉我们不支持的组件，我们可以添加对它们的支持)\n  * 客户端：从 Spring 的 `DiscoveryClient` (所有变种) 读取服务的目标地址\n\n* 支持[Spring Sleuth](https://github.com/spring-cloud/spring-cloud-sleuth)作为分布式链路跟踪解决方案(如果[brave-instrument-grpc](https://mvnrepository.com/artifact/io.zipkin.brave/brave-instrumentation-grpc)存在)\n\n* 支持全局和自定义的 gRPC 服务端/客户端拦截器\n\n* 支持metric (基于[micrometer](https://micrometer.io/)/[actuator](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-project/spring-boot-actuator) )\n\n* 也适用于 (non-shaded) grpc-netty\n\n## 版本\n\n最新版本是 `3.1.0.RELEASE` 它能跟 Spring-Boot `3.2.4` 和 Spring-Cloud `2023.0.0` 搭配使用。 但它也与各种其他版本兼容。 我们的 [文档](https://yidongnan.github.io/grpc-spring-boot-starter/en/versions.html) 中可以找到所有版本及其相应的库版本的概览。\n\n**注意:** 该项目也可以在没有 Spring-Boot 的情况下使用，但是您需要手动配置一些 bean。\n\n## 用法\n\n### gRPC 服务端 + 客户端\n\n使用以下命令添加 Maven 依赖项：\n\n````xml\n\u003cdependency\u003e\n  \u003cgroupId\u003enet.devh\u003c/groupId\u003e\n  \u003cartifactId\u003egrpc-spring-boot-starter\u003c/artifactId\u003e\n  \u003cversion\u003e3.1.0.RELEASE\u003c/version\u003e\n\u003c/dependency\u003e\n````\n\n使用 Gradle 添加依赖：\n\n````gradle\ndependencies {\n  implementation 'net.devh:grpc-spring-boot-starter:3.1.0.RELEASE'\n}\n````\n\n### gRPC 服务端\n\n使用以下命令添加 Maven 依赖项：\n\n````xml\n\u003cdependency\u003e\n  \u003cgroupId\u003enet.devh\u003c/groupId\u003e\n  \u003cartifactId\u003egrpc-server-spring-boot-starter\u003c/artifactId\u003e\n  \u003cversion\u003e3.1.0.RELEASE\u003c/version\u003e\n\u003c/dependency\u003e\n````\n\n使用 Gradle 添加依赖项：\n\n````gradle\ndependencies {\n  implementation 'net.devh:grpc-server-spring-boot-starter:3.1.0.RELEASE'\n}\n````\n\n在服务端接口实现类上添加 `@GrpcService` 注解。\n\n````java\n@GrpcService\npublic class GrpcServerService extends GreeterGrpc.GreeterImplBase {\n\n    @Override\n    public void sayHello(HelloRequest req, StreamObserver\u003cHelloReply\u003e responseObserver) {\n        HelloReply reply = HelloReply.newBuilder().setMessage(\"Hello ==\u003e \" + req.getName()).build();\n        responseObserver.onNext(reply);\n        responseObserver.onCompleted();\n    }\n\n}\n````\n\n默认情况下，gRPC 服务器将监听端口 `9090`。 端口的配置和其他的 [设置](grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/config/GrpcServerProperties.java) 可以通过 Spring 的属性机制进行更改。 服务端的配置使用 `grpc.server.` 前缀。\n\n详情请参阅我们的[文档](https://yidongnan.github.io/grpc-spring-boot-starter/)。\n\n### gRPC 客户端\n\n使用一下命令添加 Maven 依赖项：\n\n````xml\n\u003cdependency\u003e\n  \u003cgroupId\u003enet.devh\u003c/groupId\u003e\n  \u003cartifactId\u003egrpc-client-spring-boot-starter\u003c/artifactId\u003e\n  \u003cversion\u003e3.1.0.RELEASE\u003c/version\u003e\n\u003c/dependency\u003e\n````\n\n使用 Gradle 添加依赖项：\n\n````gradle\ndependencies {\n  compile 'net.devh:grpc-client-spring-boot-starter:3.1.0.RELEASE'\n}\n````\n\n在 grpc 客户端的的 stub 字段上添加 `@GrpcClient(serverName)` 注解。\n\n* 请不要将 @GrpcClient 与 `@Autowireed` 或 `@Inject` 一起使用。\n\n  ````java\n  @GrpcClient(\"gRPC server name\")\n  private GreeterGrpc.GreeterBlockingStub greeterStub;\n  ````\n\n**注意:** 你可以将相同的 grpc 服务端名称用于多个 channel， 也可以使用不同的 stub （甚至使用不同的 stub 拦截器）\n\n然后您可以向您的服务器发送查询，就像这样：\n\n````java\nHelloReply response = stub.sayHello(HelloRequest.newBuilder().setName(name).build());\n````\n\n可以单独配置每个客户端的目标地址。 但在某些情况下，您可以仅依靠默认配置。 您可以通过 `NameResolver.Factory` Bean 类自定义默认的 url 映射。 如果您没有配置那个Bean，那么默认的 uri 将使用默认方案和名称(如：`dns:\u003cname\u003e`)：\n\n这些配置和其他的 [设置](grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/config/GrpcChannelProperties.java) 可以通过 Spring 的属性机制进行更改。 客户端使用`grpc.client.(serverName)。` 前缀。\n\n详情请参阅我们的[文档](https://yidongnan.github.io/grpc-spring-boot-starter/)。\n\n## 使用 (non-shaded) grpc-netty 运行\n\n这个库支持`grpc-netty`和`grpc-nety-shaded`。 后一种可能会防止与不兼容的 gRPC 版本冲突或不同 netty 版本之间的冲突。\n\n**注意:** 如果在classpath 中存在 shaded netty， 则 shaded netty 将使用有线与 non-shaded grpc-netty。\n\n您可以在 Maven 中这样使用。\n\n````xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.grpc\u003c/groupId\u003e\n    \u003cartifactId\u003egrpc-netty\u003c/artifactId\u003e\n    \u003cversion\u003e${grpcVersion}\u003c/version\u003e\n\u003c/dependency\u003e\n\n\u003c!-- For both --\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003enet.devh\u003c/groupId\u003e\n    \u003cartifactId\u003egrpc-spring-boot-starter\u003c/artifactId\u003e\n    \u003cversion\u003e...\u003c/version\u003e\n    \u003cexclusions\u003e\n        \u003cexclusion\u003e\n            \u003cgroupId\u003eio.grpc\u003c/groupId\u003e\n            \u003cartifactId\u003egrpc-netty-shaded\u003c/artifactId\u003e\n        \u003c/exclusion\u003e\n    \u003c/exclusions\u003e\n\u003c/dependency\u003e\n\u003c!-- For the server (only) --\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003enet.devh\u003c/groupId\u003e\n    \u003cartifactId\u003egrpc-server-spring-boot-starter\u003c/artifactId\u003e\n    \u003cversion\u003e...\u003c/version\u003e\n    \u003cexclusions\u003e\n        \u003cexclusion\u003e\n            \u003cgroupId\u003eio.grpc\u003c/groupId\u003e\n            \u003cartifactId\u003egrpc-netty-shaded\u003c/artifactId\u003e\n        \u003c/exclusion\u003e\n    \u003c/exclusions\u003e\n\u003c/dependency\u003e\n\u003c!-- For the client (only) --\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003enet.devh\u003c/groupId\u003e\n    \u003cartifactId\u003egrpc-client-spring-boot-starter\u003c/artifactId\u003e\n    \u003cversion\u003e...\u003c/version\u003e\n    \u003cexclusions\u003e\n        \u003cexclusion\u003e\n            \u003cgroupId\u003eio.grpc\u003c/groupId\u003e\n            \u003cartifactId\u003egrpc-netty-shaded\u003c/artifactId\u003e\n        \u003c/exclusion\u003e\n    \u003c/exclusions\u003e\n\u003c/dependency\u003e\n````\n\n类似，使用 Gradle 的如下\n\n````groovy\nimplementation \"io.grpc:grpc-netty:${grpcVersion}\"\n\nimplementation 'net.devh:grpc-spring-boot-starter:...' exclude group: 'io.grpc', module: 'grpc-netty-shaded' // For both\nimplementation 'net.devh:grpc-client-spring-boot-starter:...' exclude group: 'io.grpc', module: 'grpc-netty-shaded' // For the client (only)\nimplementation 'net.devh:grpc-server-spring-boot-starter:...' exclude group: 'io.grpc', module: 'grpc-netty-shaded' // For the server (only)\n````\n\n## 示例项目\n\n在 [这里](examples)可以查看更多关于该项目的示例。\n\n## 排除故障\n\n请参阅我们的[文档](https://yidongnan.github.io/grpc-spring-boot-starter/en/trouble-shooting)寻求帮助。\n\n## 参与贡献\n\n欢迎您对项目作出任何贡献。 详见[CONTRIBUTING.md](CONTRIBUTING.md)。\n","funding_links":[],"categories":["Language-Specific"],"sub_categories":["Java"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrpc-ecosystem%2Fgrpc-spring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrpc-ecosystem%2Fgrpc-spring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrpc-ecosystem%2Fgrpc-spring/lists"}