Skip to content

Commit c248d3e

Browse files
committed
Add Spring Boot 3 integration modules
Motivation: Spring 6 and Spring Boot 3 have been released. https://spring.io/blog/2022/11/24/spring-boot-3-0-goes-ga Note that the added modules will not be published until we refactor `spring-boot2-autoconfigure` internals. Modifications: - Add Spring Boot 3 integrations symmetirically with Spring Boot 2. - `publish` flags are not added intentionally. - Set the release target for Spring Boot 3 and examples to Java 17. - Add `PortUtil` and migrate off `SocketUtils`. - Migrate AutoConfiguration in spring.factories to `o.s.b.a.AutoConfiguration.imports`. https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.7-Release-Notes#new-autoconfiguration-annotation - Change `management.metrics.export.defaults.enabled` to `management.promethus.metrics.export.enabled` in tests spring-projects/spring-boot#30381 - Fix compile errors in the webflux integration - Migrate moved `LocalServerPort` and `LocalManagementPort`. Depedencies: - Add Spring Boot 3.0.0 - Add `hibernate-validator 8.0.0 - Bump Micrometer into 1.10.2 - Add Jakarta dependencies - jakarta-inject 2.0.1 - jakarta-validation 3.0.2 - jakarta-websocket 2.1.0 Result: Experimentally set up Spring Boot 3 integrations.
1 parent d04f823 commit c248d3e

File tree

228 files changed

+641
-263
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+641
-263
lines changed

build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,15 @@ configure(projectsWithFlags('java')) {
178178
}
179179

180180
tasks.withType(JavaCompile) { task ->
181-
if (task.path.startsWith(':examples:')) {
182-
// Target Java 11 for examples.
183-
options.release.set(11)
181+
def path = task.path
182+
if (path.startsWith(':spring:boot3') || path.startsWith(':examples') || path.startsWith(':it:spring')) {
183+
// Target Java 17 for examples, Spring Boot 3 and Spring Boot integration tests.
184+
options.release.set(17)
184185
// IntelliJ fails to compile example projects with IntelliJ compiler because of a wrong target
185186
// bytecode version which is marked as Java 8 without the following options.
186187
// See https://github.com/line/armeria/pull/3712
187-
sourceCompatibility = '11'
188-
targetCompatibility = '11'
188+
sourceCompatibility = '17'
189+
targetCompatibility = '17'
189190
} else {
190191
// Target Java 8 for the rest of them.
191192
options.release.set(8)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2022 LINE Corporation
3+
*
4+
* LINE Corporation licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.linecorp.armeria.internal.common.util;
18+
19+
import java.io.IOException;
20+
import java.net.InetAddress;
21+
import java.net.ServerSocket;
22+
import java.util.Random;
23+
import java.util.concurrent.ThreadLocalRandom;
24+
25+
public final class PortUtil {
26+
27+
private static final int PORT_MIN = 1024;
28+
private static final int PORT_RANGE = 64511;
29+
private static final int PORT_MAX = PORT_MIN + PORT_RANGE;
30+
31+
public static int unusedTcpPort() {
32+
final Random random = ThreadLocalRandom.current();
33+
for (int i = 0; i < PORT_RANGE; i++) {
34+
final int candidatePort = random.nextInt(PORT_RANGE) + PORT_MIN;
35+
System.out.println(candidatePort);
36+
try (ServerSocket ignored = new ServerSocket(candidatePort, 1,
37+
InetAddress.getByName("127.0.0.1"))) {
38+
return candidatePort;
39+
} catch (IOException e) {
40+
// Port in use or unable to bind.
41+
continue;
42+
}
43+
}
44+
45+
throw new IllegalStateException(
46+
"Failed to find an unused TCP port in the range [" + PORT_MIN + ", " + PORT_MAX + "] after + " +
47+
PORT_RANGE + " attempts");
48+
}
49+
50+
private PortUtil() {}
51+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2022 LINE Corporation
3+
*
4+
* LINE Corporation licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
17+
package com.linecorp.armeria.internal.common.util;
18+
19+
import java.io.IOException;
20+
import java.net.InetSocketAddress;
21+
import java.net.ServerSocket;
22+
23+
import org.junit.jupiter.api.Test;
24+
25+
class PortUtilTest {
26+
27+
@Test
28+
void shouldAcquireUnusedPort() throws IOException {
29+
final int port = PortUtil.unusedTcpPort();
30+
try (ServerSocket serverSocket = new ServerSocket()) {
31+
// Make sure the ServerSocket is successfully bound to the port.
32+
serverSocket.bind(new InetSocketAddress("127.0.0.1", port));
33+
}
34+
}
35+
}

dependencies.toml

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ grpc-kotlin = "1.3.0"
3737
guava = "31.1-jre"
3838
hamcrest = "2.2"
3939
hbase = "1.2.6"
40-
hibernate-validator = "6.2.3.Final"
40+
hibernate-validator6 = "6.2.3.Final"
41+
hibernate-validator8 = "8.0.0.Final"
4142
j2objc = "1.3"
4243
jackson = "2.13.4"
44+
jakarta-inject = "2.0.1"
45+
jakarta-validation = "3.0.2"
46+
jakarta-websocket= "2.1.0"
4347
javax-annotation = "1.3.2"
4448
javax-inject = "1"
4549
javax-jsr311 = "1.1.1"
@@ -64,7 +68,7 @@ kotlin = "1.7.20"
6468
kotlin-coroutine = "1.6.4"
6569
ktlint-gradle-plugin = "11.0.0"
6670
logback = "1.2.11"
67-
micrometer = "1.9.4"
71+
micrometer = "1.10.2"
6872
micrometer13 = "1.3.20"
6973
mockito = "4.8.0"
7074
monix = "3.4.1"
@@ -104,13 +108,14 @@ scala3 = "3.2.0"
104108
scalafmt-gradle-plugin = "1.16.2"
105109
scalapb = "0.11.11"
106110
scalapb-json = "0.12.0"
107-
shadow-gradle-plugin = "6.1.0"
111+
shadow-gradle-plugin = "7.1.2"
108112
shibboleth-utilities = "7.5.2"
109113
snappy = "1.1.8.4"
110114
slf4j = "1.7.36"
111115
spring = "5.3.23"
112116
spring-boot1 = "1.5.22.RELEASE"
113117
spring-boot2 = "2.7.4"
118+
spring-boot3 = "3.0.0"
114119
testng = "7.5"
115120
thrift09 = { strictly = "0.9.3-1" }
116121
thrift012 = { strictly = "0.12.0" }
@@ -467,16 +472,32 @@ exclusions = [
467472

468473
# Validator is only used for examples and testings in Spring
469474
# version 7 starts using jakarta api, which isn't compatible with spring-boot2
470-
[libraries.hibernate-validator]
475+
[libraries.hibernate-validator6]
471476
module = "org.hibernate.validator:hibernate-validator"
472-
version.ref = "hibernate-validator"
477+
version.ref = "hibernate-validator6"
478+
[libraries.hibernate-validator8]
479+
module = "org.hibernate.validator:hibernate-validator"
480+
version.ref = "hibernate-validator8"
473481

474482
# We do not depend on j2objc-annotations. We just need this to stop Javadoc from
475483
# complaining about "unknown enum constant Level.FULL".
476484
[libraries.j2objc]
477485
module = "com.google.j2objc:j2objc-annotations"
478486
version.ref = "j2objc"
479487

488+
[libraries.jakarta-inject]
489+
module = "jakarta.inject:jakarta.inject-api"
490+
version.ref = "jakarta-inject"
491+
[libraries.jakarta-validation]
492+
module = "jakarta.validation:jakarta.validation-api"
493+
version.ref = "jakarta-validation"
494+
[libraries.jakarta-websocket]
495+
module = "jakarta.websocket:jakarta.websocket-api"
496+
version.ref = "jakarta-websocket"
497+
[libraries.jakarta-websocket-client]
498+
module = "jakarta.websocket:jakarta.websocket-client-api"
499+
version.ref = "jakarta-websocket"
500+
480501
[libraries.jackson-annotations]
481502
module = "com.fasterxml.jackson.core:jackson-annotations"
482503
javadocs = "https://fasterxml.github.io/jackson-annotations/javadoc/2.13/"
@@ -953,7 +974,7 @@ module = "com.thesamet.scalapb:scalapb-json4s_3"
953974
version.ref = "scalapb-json"
954975

955976
[libraries.shadow-gradle-plugin]
956-
module = "com.github.jengelman.gradle.plugins:shadow"
977+
module = "gradle.plugin.com.github.johnrengelman:shadow"
957978
version.ref = "shadow-gradle-plugin"
958979

959980
[libraries.slf4j-api]
@@ -1020,6 +1041,36 @@ exclusions = "org.springframework.boot:spring-boot-starter-reactor-netty"
10201041
module = "org.springframework.boot:spring-boot-configuration-processor"
10211042
version.ref = "spring-boot2"
10221043

1044+
[libraries.spring-boot3-actuator-autoconfigure]
1045+
module = "org.springframework.boot:spring-boot-actuator-autoconfigure"
1046+
version.ref = "spring-boot3"
1047+
[libraries.spring-boot3-autoconfigure]
1048+
module = "org.springframework.boot:spring-boot-autoconfigure"
1049+
version.ref = "spring-boot3"
1050+
[libraries.spring-boot3-starter]
1051+
module = "org.springframework.boot:spring-boot-starter"
1052+
version.ref = "spring-boot3"
1053+
javadocs = "https://docs.spring.io/spring/docs/current/javadoc-api/"
1054+
[libraries.spring-boot3-starter-actuator]
1055+
module = "org.springframework.boot:spring-boot-starter-actuator"
1056+
version.ref = "spring-boot3"
1057+
[libraries.spring-boot3-starter-security]
1058+
module = "org.springframework.boot:spring-boot-starter-security"
1059+
version.ref = "spring-boot3"
1060+
[libraries.spring-boot3-starter-test]
1061+
module = "org.springframework.boot:spring-boot-starter-test"
1062+
version.ref = "spring-boot3"
1063+
[libraries.spring-boot3-starter-web]
1064+
module = "org.springframework.boot:spring-boot-starter-web"
1065+
version.ref = "spring-boot3"
1066+
[libraries.spring-boot3-starter-webflux]
1067+
module = "org.springframework.boot:spring-boot-starter-webflux"
1068+
version.ref = "spring-boot3"
1069+
exclusions = "org.springframework.boot:spring-boot-starter-reactor-netty"
1070+
[libraries.spring-boot3-configuration-processor]
1071+
module = "org.springframework.boot:spring-boot-configuration-processor"
1072+
version.ref = "spring-boot3"
1073+
10231074
# jdk 11 is required from testng version 7.6
10241075
[libraries.testng]
10251076
module = "org.testng:testng"

examples/spring-boot-minimal-kotlin/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ plugins {
77
}
88

99
dependencies {
10-
implementation(project(":spring:boot2-starter"))
11-
implementation(libs.hibernate.validator)
10+
implementation(project(":spring:boot3-starter"))
11+
implementation(libs.hibernate.validator8)
1212

13-
implementation(project(":spring:boot2-actuator-starter"))
13+
implementation(project(":spring:boot3-actuator-starter"))
1414

1515
implementation(libs.jackson.kotlin)
1616
implementation(kotlin("reflect"))
1717
implementation(kotlin("stdlib-jdk8"))
1818

1919
testImplementation(libs.json.unit.fluent)
2020
testImplementation(libs.junit5.jupiter.api)
21-
testImplementation(libs.spring.boot2.starter.test)
21+
testImplementation(libs.spring.boot3.starter.test)
2222

2323
// Preprocessor that enables you to use KDoc to add description to REST API parameters.
2424
// If you don't want to use it, you can use the annotation

examples/spring-boot-minimal-kotlin/src/main/kotlin/example/springframework/boot/minimal/kotlin/HelloAnnotatedService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package example.springframework.boot.minimal.kotlin
33
import com.linecorp.armeria.server.annotation.ExceptionHandler
44
import com.linecorp.armeria.server.annotation.Get
55
import com.linecorp.armeria.server.annotation.Param
6+
import jakarta.validation.constraints.Size
67
import org.springframework.stereotype.Component
78
import org.springframework.validation.annotation.Validated
8-
import javax.validation.constraints.Size
99

1010
/**
1111
* Note that this is not a Spring-based component but an annotated HTTP service that leverages

examples/spring-boot-minimal-kotlin/src/main/kotlin/example/springframework/boot/minimal/kotlin/ValidationExceptionHandler.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
package example.springframework.boot.minimal.kotlin
22

3-
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
43
import com.linecorp.armeria.common.HttpRequest
54
import com.linecorp.armeria.common.HttpResponse
65
import com.linecorp.armeria.common.HttpStatus
76
import com.linecorp.armeria.server.ServiceRequestContext
87
import com.linecorp.armeria.server.annotation.ExceptionHandlerFunction
8+
import jakarta.validation.ValidationException
99
import java.time.Instant
10-
import javax.validation.ValidationException
1110

1211
/**
1312
* A sample exception handler which handles a [ValidationException].
1413
*/
1514
class ValidationExceptionHandler : ExceptionHandlerFunction {
1615

17-
private val mapper = jacksonObjectMapper()
18-
1916
override fun handleException(ctx: ServiceRequestContext, req: HttpRequest, cause: Throwable): HttpResponse {
2017
return if (cause is ValidationException) {
2118
val status = HttpStatus.BAD_REQUEST

examples/spring-boot-minimal/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ plugins {
33
}
44

55
dependencies {
6-
implementation project(':spring:boot2-starter')
7-
implementation libs.hibernate.validator
6+
implementation project(':spring:boot3-starter')
7+
implementation libs.hibernate.validator8
88

99
// Preprocessor that enables you to use JavaDoc to add description to REST API parameters.
1010
// If you don't want to use it, you can use the annotation
1111
// com.linecorp.armeria.server.annotation.Description otherwise.
1212
compileOnly project(':annotation-processor')
1313
annotationProcessor project(':annotation-processor')
1414

15-
annotationProcessor libs.spring.boot2.configuration.processor
15+
annotationProcessor libs.spring.boot3.configuration.processor
1616

17-
runtimeOnly project(':spring:boot2-actuator-starter')
17+
runtimeOnly project(':spring:boot3-actuator-starter')
1818

1919
testImplementation libs.json.unit.fluent
2020
testImplementation libs.junit5.jupiter.api
21-
testImplementation libs.spring.boot2.starter.test
21+
testImplementation libs.spring.boot3.starter.test
2222
}

examples/spring-boot-minimal/src/main/java/example/springframework/boot/minimal/HelloAnnotatedService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package example.springframework.boot.minimal;
22

3-
import javax.validation.constraints.Size;
4-
53
import org.springframework.stereotype.Component;
64
import org.springframework.validation.annotation.Validated;
75

86
import com.linecorp.armeria.server.annotation.ExceptionHandler;
97
import com.linecorp.armeria.server.annotation.Get;
108
import com.linecorp.armeria.server.annotation.Param;
119

10+
import jakarta.validation.constraints.Size;
11+
1212
/**
1313
* Note that this is not a Spring-based component but an annotated HTTP service that leverages
1414
* Armeria's built-in annotations.

examples/spring-boot-minimal/src/main/java/example/springframework/boot/minimal/ValidationExceptionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
import java.time.Instant;
66

7-
import javax.validation.ValidationException;
8-
97
import com.fasterxml.jackson.annotation.JsonCreator;
108
import com.fasterxml.jackson.annotation.JsonProperty;
119

@@ -15,6 +13,8 @@
1513
import com.linecorp.armeria.server.ServiceRequestContext;
1614
import com.linecorp.armeria.server.annotation.ExceptionHandlerFunction;
1715

16+
import jakarta.validation.ValidationException;
17+
1818
/**
1919
* A sample exception handler which handles a {@link ValidationException}.
2020
*/

0 commit comments

Comments
 (0)