Browse Source

Merge pull request #49710 from deejay1

* kotlin-examples-redux:
  Polish "Add some more Kotlin examples and trivial style fixes"
  Add some more Kotlin examples and trivial style fixes

Closes gh-49710
pull/49718/head
Stéphane Nicoll 2 weeks ago
parent
commit
7624cbb924
  1. 3
      spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc
  2. 2
      spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/errorpages/MyErrorViewResolver.java
  3. 5
      spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/developingautoconfiguration/testing/MyConditionEvaluationReportingTests.kt
  4. 14
      spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/devtools/restart/disable/MyApplication.kt
  5. 3
      spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/springapplication/MyApplication.kt
  6. 35
      spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/embeddedcontainer/applicationcontext/MyDemoBean.kt
  7. 32
      spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/jersey/MyEndpoint.kt
  8. 29
      spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/jersey/MyJerseyConfig.kt

3
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 @@ -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,

2
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 { @@ -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;
}

5
spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/developingautoconfiguration/testing/MyConditionEvaluationReportingTests.kt

@ -29,8 +29,9 @@ class MyConditionEvaluationReportingTests { @@ -29,8 +29,9 @@ class MyConditionEvaluationReportingTests {
fun autoConfigTest() {
ApplicationContextRunner()
.withInitializer(ConditionEvaluationReportLoggingListener.forLogLevel(LogLevel.INFO))
.run { context: AssertableApplicationContext? -> }
.run { context: AssertableApplicationContext? ->
// Test something...
}
}
}

14
spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/devtools/restart/disable/MyApplication.kt

@ -16,17 +16,13 @@ @@ -16,17 +16,13 @@
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<String>) {
System.setProperty("spring.devtools.restart.enabled", "false")
SpringApplication.run(MyApplication::class.java, *args)
}
class MyApplication
fun main(args: Array<String>) {
System.setProperty("spring.devtools.restart.enabled", "false")
runApplication<MyApplication>(*args)
}

3
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 @@ -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<String>) {
runApplication<MyApplication>(*args)
}

35
spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/embeddedcontainer/applicationcontext/MyDemoBean.kt

@ -0,0 +1,35 @@ @@ -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<ApplicationStartedEvent> {
@Suppress("unused")
private var servletContext: ServletContext? = null
override fun onApplicationEvent(event: ApplicationStartedEvent) {
val applicationContext: ApplicationContext = event.applicationContext
this.servletContext = (applicationContext as WebApplicationContext).servletContext
}
}

32
spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/jersey/MyEndpoint.kt

@ -0,0 +1,32 @@ @@ -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"
}
}

29
spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/jersey/MyJerseyConfig.kt

@ -0,0 +1,29 @@ @@ -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)
}
}
Loading…
Cancel
Save