From d7078e08b89a3644d158f04998ebb19399986297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Jerna=C5=9B?= Date: Mon, 23 Mar 2026 13:11:52 +0100 Subject: [PATCH 1/2] Add some more Kotlin examples and trivial style fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See gh-49710 Signed-off-by: Łukasz Jernaś --- .../reference/pages/features/kotlin.adoc | 3 +- .../errorpages/MyErrorViewResolver.java | 2 +- .../MyConditionEvaluationReportingTests.kt | 5 +-- .../devtools/restart/disable/MyApplication.kt | 13 +++---- .../springapplication/MyApplication.kt | 3 +- .../applicationcontext/MyDemoBean.kt | 35 +++++++++++++++++++ .../docs/web/servlet/jersey/MyEndpoint.kt | 32 +++++++++++++++++ .../docs/web/servlet/jersey/MyJerseyConfig.kt | 29 +++++++++++++++ 8 files changed, 108 insertions(+), 14 deletions(-) create mode 100644 spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/embeddedcontainer/applicationcontext/MyDemoBean.kt create mode 100644 spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/jersey/MyEndpoint.kt create mode 100644 spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/jersey/MyJerseyConfig.kt diff --git a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc index f46ba392e6d..ec3ba2cb922 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc @@ -121,7 +121,8 @@ javadoc:org.springframework.boot.context.properties.ConfigurationProperties[form data class KotlinExampleProperties( val name: String, val description: String, - val myService: MyService) { + val myService: MyService +) { data class MyService( val apiToken: String, diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/errorpages/MyErrorViewResolver.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/errorpages/MyErrorViewResolver.java index 5effa076d37..2b338243359 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/errorpages/MyErrorViewResolver.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/errorpages/MyErrorViewResolver.java @@ -31,7 +31,7 @@ public class MyErrorViewResolver implements ErrorViewResolver { // Use the request or status to optionally return a ModelAndView if (status == HttpStatus.INSUFFICIENT_STORAGE) { // We could add custom model values here - new ModelAndView("myview"); + return new ModelAndView("myview"); } return null; } diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/developingautoconfiguration/testing/MyConditionEvaluationReportingTests.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/developingautoconfiguration/testing/MyConditionEvaluationReportingTests.kt index 00a30745cde..441eee62e66 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/developingautoconfiguration/testing/MyConditionEvaluationReportingTests.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/developingautoconfiguration/testing/MyConditionEvaluationReportingTests.kt @@ -29,8 +29,9 @@ class MyConditionEvaluationReportingTests { fun autoConfigTest() { ApplicationContextRunner() .withInitializer(ConditionEvaluationReportLoggingListener.forLogLevel(LogLevel.INFO)) - .run { context: AssertableApplicationContext? -> } + .run { context: AssertableApplicationContext? -> + // Test something... + } } } - diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/devtools/restart/disable/MyApplication.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/devtools/restart/disable/MyApplication.kt index d3e24276e68..467a9191277 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/devtools/restart/disable/MyApplication.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/devtools/restart/disable/MyApplication.kt @@ -18,15 +18,12 @@ package org.springframework.boot.docs.using.devtools.restart.disable import org.springframework.boot.SpringApplication import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.runApplication @SpringBootApplication -object MyApplication { - - @JvmStatic - fun main(args: Array) { - System.setProperty("spring.devtools.restart.enabled", "false") - SpringApplication.run(MyApplication::class.java, *args) - } +class MyApplication +fun main(args: Array) { + System.setProperty("spring.devtools.restart.enabled", "false") + runApplication(*args) } - diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/springapplication/MyApplication.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/springapplication/MyApplication.kt index 2f7bbdd303e..5211675a940 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/springapplication/MyApplication.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/springapplication/MyApplication.kt @@ -19,11 +19,10 @@ package org.springframework.boot.docs.using.usingthespringbootapplicationannotat import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication -// same as @SpringBootConfiguration @EnableAutoConfiguration @ComponentScan +// Same as @SpringBootConfiguration @EnableAutoConfiguration @ComponentScan @SpringBootApplication class MyApplication fun main(args: Array) { runApplication(*args) } - diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/embeddedcontainer/applicationcontext/MyDemoBean.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/embeddedcontainer/applicationcontext/MyDemoBean.kt new file mode 100644 index 00000000000..7cce3c56f74 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/embeddedcontainer/applicationcontext/MyDemoBean.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.web.servlet.embeddedcontainer.applicationcontext + +import jakarta.servlet.ServletContext +import org.springframework.boot.context.event.ApplicationStartedEvent +import org.springframework.context.ApplicationContext +import org.springframework.context.ApplicationListener +import org.springframework.web.context.WebApplicationContext + +class MyDemoBean : ApplicationListener { + + @Suppress("unused") + private var servletContext: ServletContext? = null + + override fun onApplicationEvent(event: ApplicationStartedEvent) { + val applicationContext: ApplicationContext = event.applicationContext + this.servletContext = (applicationContext as WebApplicationContext).servletContext + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/jersey/MyEndpoint.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/jersey/MyEndpoint.kt new file mode 100644 index 00000000000..74a66c171d3 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/jersey/MyEndpoint.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.web.servlet.jersey + +import jakarta.ws.rs.GET +import jakarta.ws.rs.Path +import org.springframework.stereotype.Component + +@Component +@Path("/hello") +class MyEndpoint { + + @GET + fun message(): String { + return "Hello" + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/jersey/MyJerseyConfig.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/jersey/MyJerseyConfig.kt new file mode 100644 index 00000000000..9397e3ba698 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/jersey/MyJerseyConfig.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.web.servlet.jersey + +import org.glassfish.jersey.server.ResourceConfig +import org.springframework.stereotype.Component + +@Component +class MyJerseyConfig : ResourceConfig() { + + init { + register(MyEndpoint::class.java) + } + +} From e15755bc808931adcd21792205588146b6cbfda3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Mon, 23 Mar 2026 16:19:48 +0100 Subject: [PATCH 2/2] Polish "Add some more Kotlin examples and trivial style fixes" See gh-49710 --- .../boot/docs/using/devtools/restart/disable/MyApplication.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/devtools/restart/disable/MyApplication.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/devtools/restart/disable/MyApplication.kt index 467a9191277..2bc9f362c75 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/devtools/restart/disable/MyApplication.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/devtools/restart/disable/MyApplication.kt @@ -16,7 +16,6 @@ package org.springframework.boot.docs.using.devtools.restart.disable -import org.springframework.boot.SpringApplication import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication