Skip to content

Commit 8668518

Browse files
committed
Merge branch 'master' into pr/496
2 parents 89a1a9e + d2d50ed commit 8668518

File tree

30 files changed

+553
-59
lines changed

30 files changed

+553
-59
lines changed

README-zh-CN.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ QQ交流群:294712648
3737

3838
2.x.x.RELEASE 支持 Spring Boot 2.1.x/2.2.x 和 Spring Cloud Greenwich / Hoxton。
3939

40-
最新版本: `2.10.1.RELEASE`
40+
最新版本: `2.11.0.RELEASE`
4141

4242
( `2.4.0.RELEASE` 用于 Spring Boot 2.0.x & Spring Cloud Finchy).
4343

@@ -57,15 +57,15 @@ QQ交流群:294712648
5757
<dependency>
5858
<groupId>net.devh</groupId>
5959
<artifactId>grpc-spring-boot-starter</artifactId>
60-
<version>2.10.1.RELEASE</version>
60+
<version>2.11.0.RELEASE</version>
6161
</dependency>
6262
````
6363

6464
Gradle:
6565

6666
````gradle
6767
dependencies {
68-
compile 'net.devh:grpc-spring-boot-starter:2.10.1.RELEASE'
68+
compile 'net.devh:grpc-spring-boot-starter:2.11.0.RELEASE'
6969
}
7070
````
7171

@@ -77,15 +77,15 @@ dependencies {
7777
<dependency>
7878
<groupId>net.devh</groupId>
7979
<artifactId>grpc-server-spring-boot-starter</artifactId>
80-
<version>2.10.1.RELEASE</version>
80+
<version>2.11.0.RELEASE</version>
8181
</dependency>
8282
````
8383

8484
Gradle:
8585

8686
````gradle
8787
dependencies {
88-
compile 'net.devh:grpc-server-spring-boot-starter:2.10.1.RELEASE'
88+
compile 'net.devh:grpc-server-spring-boot-starter:2.11.0.RELEASE'
8989
}
9090
````
9191

@@ -117,15 +117,15 @@ public class GrpcServerService extends GreeterGrpc.GreeterImplBase {
117117
<dependency>
118118
<groupId>net.devh</groupId>
119119
<artifactId>grpc-client-spring-boot-starter</artifactId>
120-
<version>2.10.1.RELEASE</version>
120+
<version>2.11.0.RELEASE</version>
121121
</dependency>
122122
````
123123

124124
Gradle:
125125

126126
````gradle
127127
dependencies {
128-
compile 'net.devh:grpc-client-spring-boot-starter:2.10.1.RELEASE'
128+
compile 'net.devh:grpc-client-spring-boot-starter:2.11.0.RELEASE'
129129
}
130130
````
131131
在 grpc 客户端的的 stub 字段上添加 `@GrpcClient(serverName)` 注解。

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ README: [English](README.md) | [中文](README-zh-CN.md)
5252

5353
2.x.x.RELEASE supports Spring Boot 2.1.x/2.2.x & Spring Cloud Greenwich/Hoxton.
5454

55-
The latest version: ``2.10.1.RELEASE``
55+
The latest version: ``2.11.0.RELEASE``
5656

5757
(Use `2.4.0.RELEASE` for Spring Boot 2.0.x & Spring Cloud Finchley).
5858

@@ -72,15 +72,15 @@ To add a dependency using Maven, use the following:
7272
<dependency>
7373
<groupId>net.devh</groupId>
7474
<artifactId>grpc-spring-boot-starter</artifactId>
75-
<version>2.10.1.RELEASE</version>
75+
<version>2.11.0.RELEASE</version>
7676
</dependency>
7777
````
7878

7979
To add a dependency using Gradle:
8080

8181
````gradle
8282
dependencies {
83-
implementation 'net.devh:grpc-spring-boot-starter:2.10.1.RELEASE'
83+
implementation 'net.devh:grpc-spring-boot-starter:2.11.0.RELEASE'
8484
}
8585
````
8686

@@ -92,15 +92,15 @@ To add a dependency using Maven, use the following:
9292
<dependency>
9393
<groupId>net.devh</groupId>
9494
<artifactId>grpc-server-spring-boot-starter</artifactId>
95-
<version>2.10.1.RELEASE</version>
95+
<version>2.11.0.RELEASE</version>
9696
</dependency>
9797
````
9898

9999
To add a dependency using Gradle:
100100

101101
````gradle
102102
dependencies {
103-
implementation 'net.devh:grpc-server-spring-boot-starter:2.10.1.RELEASE'
103+
implementation 'net.devh:grpc-server-spring-boot-starter:2.11.0.RELEASE'
104104
}
105105
````
106106

@@ -134,15 +134,15 @@ To add a dependency using Maven, use the following:
134134
<dependency>
135135
<groupId>net.devh</groupId>
136136
<artifactId>grpc-client-spring-boot-starter</artifactId>
137-
<version>2.10.1.RELEASE</version>
137+
<version>2.11.0.RELEASE</version>
138138
</dependency>
139139
````
140140

141141
To add a dependency using Gradle:
142142

143143
````gradle
144144
dependencies {
145-
compile 'net.devh:grpc-client-spring-boot-starter:2.10.1.RELEASE'
145+
compile 'net.devh:grpc-client-spring-boot-starter:2.11.0.RELEASE'
146146
}
147147
````
148148

build.gradle

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,25 @@ buildscript {
99
}
1010
}
1111
ext {
12-
projectVersion = '2.11.0-SNAPSHOT'
12+
projectVersion = '2.12.0-SNAPSHOT'
1313

1414
// https://github.com/grpc/grpc-java/releases
15-
grpcVersion = '1.35.0'
15+
grpcVersion = '1.37.0'
16+
17+
// https://github.com/google/guava/releases
18+
guavaVersion = '30.1.1-jre'
1619
// https://github.com/protocolbuffers/protobuf/releases
17-
protobufVersion = '3.14.0'
20+
protobufVersion = '3.15.8'
1821
protobufGradlePluginVersion = '0.8.12'
1922

2023
// https://github.com/spring-projects/spring-boot/releases
21-
springBootVersion = '2.3.8.RELEASE'
24+
springBootVersion = '2.4.5'
2225
// https://github.com/spring-cloud/spring-cloud-release/releases
23-
springCloudVersion = 'Hoxton.SR9'
26+
springCloudVersion = '2020.0.2'
2427
// https://github.com/alibaba/spring-cloud-alibaba/releases
25-
springCloudAlibabaNacosVersion = '2.2.3.RELEASE'
28+
springCloudAlibabaNacosVersion = '2021.1'
2629
// https://github.com/spring-projects/spring-security-oauth/releases
27-
springSecurityOAuthVersion = '2.5.0.RELEASE'
30+
springSecurityOAuthVersion = '2.5.1.RELEASE'
2831

2932
lombokPluginVersion = '4.0.0'
3033
versioningPluginVersion = '2.14.0'
@@ -38,10 +41,10 @@ plugins {
3841
id 'org.springframework.boot' version "${springBootVersion}" apply false
3942
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
4043
id 'net.nemerosa.versioning' version '2.14.0'
41-
id 'com.google.protobuf' version '0.8.14'
44+
id 'com.google.protobuf' version '0.8.15'
4245
id 'io.franzbecker.gradle-lombok' version '4.0.0' apply false
4346
id 'com.github.ben-manes.versions' version '0.36.0' // gradle dependencyUpdates
44-
id 'com.diffplug.spotless' version '5.9.0'
47+
id 'com.diffplug.spotless' version '5.11.0'
4548
}
4649

4750
// If you attempt to build without the `--scan` parameter in `gradle 6.0+` it will cause a build error that it can't find
@@ -57,7 +60,7 @@ if (hasProperty('buildScan')) {
5760
wrapper {
5861
// Update using:
5962
// ./gradlew wrapper --gradle-version=6.5 --distribution-type=bin
60-
gradleVersion = '6.7.1'
63+
gradleVersion = '7.0'
6164
}
6265

6366
def buildTimeAndDate = OffsetDateTime.now()
@@ -95,11 +98,20 @@ allprojects {
9598
}
9699
format('misc') {
97100
target('**/*.gradle', '**/*.md', '**/*.yml')
101+
targetExclude('**/build/**/*.*')
98102
trimTrailingWhitespace()
99103
endWithNewline()
100104
}
101105
}
102106

107+
normalization {
108+
runtimeClasspath {
109+
metaInf{
110+
ignoreAttribute('Build-Time')
111+
}
112+
}
113+
}
114+
103115
// Copy LICENSE
104116
tasks.withType(Jar) {
105117
from(project.rootDir) {
@@ -155,7 +167,9 @@ allprojects { project ->
155167
imports {
156168
mavenBom "org.springframework.boot:spring-boot-starter-parent:${springBootVersion}"
157169
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
170+
mavenBom "com.alibaba.cloud:spring-cloud-alibaba-dependencies:${springCloudAlibabaNacosVersion}"
158171
mavenBom "com.google.protobuf:protobuf-bom:${protobufVersion}"
172+
mavenBom "com.google.guava:guava-bom:${guavaVersion}"
159173
mavenBom "io.grpc:grpc-bom:${grpcVersion}"
160174
mavenBom "org.junit:junit-bom:5.7.0"
161175
}

docs/en/client/configuration.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This section describes how you can configure your grpc-spring-boot-starter clien
1313
- [ClientInterceptor](#clientinterceptor)
1414
- [StubFactory](#stubfactory)
1515
- [StubTransformer](#stubtransformer)
16+
- [Custom NameResolverProvider](#custom-nameresolverprovider)
1617

1718
## Additional Topics <!-- omit in toc -->
1819

@@ -80,7 +81,8 @@ There are a number of supported schemes, that you can use to determine the targe
8081
You can define custom
8182
[`NameResolverProvider`s](https://javadoc.io/page/io.grpc/grpc-all/latest/io/grpc/NameResolverProvider.html) those
8283
will be picked up, by either via Java's `ServiceLoader` or from spring's application context and registered in
83-
the `NameResolverRegistry`.
84+
the `NameResolverRegistry`. \
85+
See also [Custom NameResolverProvider](#custom-nameresolverprovider)
8486

8587
If you don't define an address it will be guessed:
8688

@@ -243,6 +245,23 @@ You can also use `StubTransformer`s to add custom `ClientInterceptor`s to your s
243245

244246
> **Note**: The `StubTransformer`s are applied after the `@GrpcClient#interceptors(Names)` have been added.
245247
248+
## Custom NameResolverProvider
249+
250+
Sometimes you might have some custom logic that decides which server you wish to connect to, you can achieve this
251+
using a custom `NameResolverProvider`.
252+
253+
> **Note:** This can only be used to decide this on an application level and not on a per request level.
254+
255+
This library provides some `NameResolverProvider`s itself so you can use them as a
256+
[reference](https://github.com/yidongnan/grpc-spring-boot-starter/tree/master/grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/nameresolver).
257+
258+
You can register your `NameResolverProvider` by adding it to `META-INF/services/io.grpc.NameResolverProvider` for Java's
259+
`ServiceLoader` or adding it your spring context. If you wish to use some spring beans inside your `NameResolver`, then
260+
you have to define it via spring context (unless you wish to use `static`).
261+
262+
> **Note:** `NameResolverProvider`s are registered gloablly, so might run into issues if you boot up two or more
263+
> applications simulataneosly in the same JVM (e.g. during tests).
264+
246265
## Additional Topics <!-- omit in toc -->
247266

248267
- [Getting Started](getting-started.md)

docs/en/trouble-shooting.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ are also affected. If there is no such topic, feel free to open a new one as des
99

1010
## Table of Contents
1111

12+
- [NoClassDefFoundError, ClassNotFoundException, NoSuchMethodError, AbstractMethodError](#noclassdeffounderror-classnotfoundexception-nosuchmethoderror-abstractmethoderror)
1213
- [Transport failed](#transport-failed)
1314
- [Network closed for unknown reason](#network-closed-for-unknown-reason)
1415
- [Could not find TLS ALPN provider](#could-not-find-tls-alpn-provider)
@@ -18,6 +19,52 @@ are also affected. If there is no such topic, feel free to open a new one as des
1819
- [Client fails to resolve domain name](#client-fails-to-resolve-domain-name)
1920
- [Creating issues / asking questions](#creating-issues)
2021

22+
## NoClassDefFoundError, ClassNotFoundException, NoSuchMethodError, AbstractMethodError
23+
24+
### Example
25+
26+
````txt
27+
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'client' defined in file [~/.../MyGrpcClient.class]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: io/grpc/TlsChannelCredentials$Feature
28+
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602)
29+
[...]
30+
Caused by: java.lang.NoClassDefFoundError: io/grpc/TlsChannelCredentials$Feature
31+
at io.grpc.netty.ProtocolNegotiators.<clinit>(ProtocolNegotiators.java:92)
32+
````
33+
34+
### The Problem
35+
36+
The server/client does not start because some class or method is missing. \
37+
This is usually the case if the grpc-libraries use slightly different versions.
38+
39+
### The solution
40+
41+
Make sure to use exactly the same version for all `grpc-java` versions.
42+
43+
Add the following entry to your `dependencyManagement` section of your project:
44+
45+
````xml
46+
<dependency>
47+
<groupId>io.grpc</groupId>
48+
<artifactId>grpc-bom</artifactId>
49+
<version>${grpcVersion}</version>
50+
<type>pom</type>
51+
<scope>import</scope>
52+
</dependency>
53+
````
54+
55+
You can use a similar approach for gradle:
56+
57+
````groovy
58+
dependencyManagement {
59+
imports {
60+
mavenBom "io.grpc:grpc-bom:${grpcVersion}"
61+
````
62+
63+
> **Note:** grpc-spring-boot-starter isn't strictly bound to a specific version of grpc-java, so you can also use this
64+
> to change the version of grpc-java you are using in your project.
65+
66+
See also [Could not find TLS ALPN provider](#could-not-find-tls-alpn-provider)
67+
2168
## Transport failed
2269

2370
### Server-side

docs/en/versions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ Current version.
4747

4848
| Version | spring-boot | gRPC | Date |
4949
|:-------:|:-----------:|:----:| ---: |
50-
| 2.12.0* | 2.4.x | 1.34.1 | TBA |
51-
| 2.11.0* | 2.3.8 | 1.35.0 | Feb, 2021 |
50+
| 2.12.0* | 2.4.5 | 1.37.0 | Apr, 2021 |
51+
| 2.11.0 | 2.3.8 | 1.35.0 | Feb, 2021 |
5252
| 2.10.1 | 2.3.3 | 1.31.1 | Aug, 2020 |
5353
| 2.10.0 | 2.3.3 | 1.31.1 | Aug, 2020 |
5454
| 2.9.0 | 2.3.1 | 1.30.0 | Jun, 2020 |

docs/zh-CN/examples.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
- [客户端](https://github.com/yidongnan/grpc-spring-boot-starter/tree/master/examples/cloud-grpc-client)
2424
- [说明](https://github.com/yidongnan/grpc-spring-boot-starter/tree/master/examples#cloud-mode)
2525

26+
## Cloud-Nacos 示例
27+
28+
使用 nacos 服务发现的 Cloud 环境。
29+
30+
- [服务端](https://github.com/yidongnan/grpc-spring-boot-starter/tree/master/examples/cloud-grpc-server-nacos)
31+
- [客户端](https://github.com/yidongnan/grpc-spring-boot-starter/tree/master/examples/cloud-grpc-client-nacos)
32+
- [说明](https://github.com/yidongnan/grpc-spring-boot-starter/tree/master/examples#cloud-mode)
33+
2634
## 基础认证示例
2735

2836
演示了 grpc 跟 spring security 的设置。 为了简单起见,此设置使用 Basic 身份验证,但也可以为其使用其他身份验证机制。

docs/zh-CN/versions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838

3939
| 版本 | spring-boot | gRPC | 日期 |
4040
|:---------:|:-----------:|:------:| ----------:|
41-
| 2.11.0* | 2.3.3 | 1.31.1 | 待定 |
41+
| 2.12.0* | 2.4.x | 1.34.1 | 待定 |
42+
| 2.11.0 | 2.3.3 | 1.31.1 | 2021年02月 |
4243
| 2.10.1 | 2.3.3 | 1.31.1 | 2020年08月 |
4344
| 2.10.0 | 2.3.3 | 1.31.1 | 2020年08月 |
4445
| 2.9.0 | 2.3.0 | 1.30.0 | 2020年06月 |

examples/cloud-eureka-server/src/main/resources/bootstrap.yml renamed to examples/cloud-eureka-server/src/main/resources/application.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ eureka:
1717
registerWithEureka: false
1818
fetchRegistry: false
1919
serviceUrl:
20-
defaultZone: http://localhost:8761/eureka/
20+
defaultZone: http://localhost:8761/eureka/
2121
server:
2222
enable-self-preservation: false
2323

24-
endpoints:
25-
shutdown:
26-
enabled: true
24+
management:
25+
endpoint:
26+
shutdown:
27+
enabled: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
plugins {
2+
id 'org.springframework.boot'
3+
}
4+
5+
dependencies {
6+
implementation 'org.springframework.boot:spring-boot-starter-web'
7+
implementation 'com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery'
8+
implementation project(':grpc-client-spring-boot-starter') // replace to implementation("net.devh:grpc-client-spring-boot-starter:${springBootGrpcVersion}")
9+
implementation project(':examples:grpc-lib')
10+
}

0 commit comments

Comments
 (0)