Polish 'Add Kotlin alternatives to Java documentation samples'

See gh-29499
pull/29745/head
Phillip Webb 3 years ago
parent 197afff1d6
commit d212243eef

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,14 +24,24 @@ import org.springframework.boot.web.servlet.ServletContextInitializer
import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Configuration
import java.io.IOException import java.io.IOException
import javax.servlet.* import java.util.Collections.emptySet
import javax.servlet.GenericServlet
import javax.servlet.Servlet
import javax.servlet.ServletContainerInitializer
import javax.servlet.ServletContext
import javax.servlet.ServletException
import javax.servlet.ServletRequest
import javax.servlet.ServletResponse
import kotlin.jvm.Throws import kotlin.jvm.Throws
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class MyCloudFoundryConfiguration { class MyCloudFoundryConfiguration {
@Bean @Bean
fun servletWebServerFactory(): TomcatServletWebServerFactory { fun servletWebServerFactory(): TomcatServletWebServerFactory {
return object : TomcatServletWebServerFactory() { return object : TomcatServletWebServerFactory() {
override fun prepareContext(host: Host, initializers: Array<ServletContextInitializer>) { override fun prepareContext(host: Host, initializers: Array<ServletContextInitializer>) {
super.prepareContext(host, initializers) super.prepareContext(host, initializers)
val child = StandardContext() val child = StandardContext()
@ -42,17 +52,20 @@ class MyCloudFoundryConfiguration {
child.crossContext = true child.crossContext = true
host.addChild(child) host.addChild(child)
} }
} }
} }
private fun getServletContextInitializer(contextPath: String): ServletContainerInitializer { private fun getServletContextInitializer(contextPath: String): ServletContainerInitializer {
return ServletContainerInitializer { classes: Set<Class<*>?>?, context: ServletContext -> return ServletContainerInitializer { classes: Set<Class<*>?>?, context: ServletContext ->
val servlet: Servlet = object : GenericServlet() { val servlet: Servlet = object : GenericServlet() {
@Throws(ServletException::class, IOException::class) @Throws(ServletException::class, IOException::class)
override fun service(req: ServletRequest, res: ServletResponse) { override fun service(req: ServletRequest, res: ServletResponse) {
val context = req.servletContext.getContext(contextPath) val servletContext = req.servletContext.getContext(contextPath)
context.getRequestDispatcher("/cloudfoundryapplication").forward(req, res) servletContext.getRequestDispatcher("/cloudfoundryapplication").forward(req, res)
} }
} }
context.addServlet("cloudfoundry", servlet).addMapping("/*") context.addServlet("cloudfoundry", servlet).addMapping("/*")
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,18 +23,18 @@ import reactor.core.publisher.Mono
@Component @Component
class MyReactiveHealthIndicator : ReactiveHealthIndicator { class MyReactiveHealthIndicator : ReactiveHealthIndicator {
override fun health(): Mono<Health> { override fun health(): Mono<Health> {
// @formatter:off // @formatter:off
return doHealthCheck()!!.onErrorResume { exception: Throwable? -> return doHealthCheck()!!.onErrorResume { exception: Throwable? ->
Mono.just( Mono.just(Health.Builder().down(exception).build())
Health.Builder().down(exception).build()
)
} }
// @formatter:on // @formatter:on
} }
private fun doHealthCheck(): Mono<Health>? { private fun doHealthCheck(): Mono<Health>? {
// perform some specific health check // perform some specific health check
return /**/null return /**/ null
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,15 +22,18 @@ import org.springframework.stereotype.Component
@Component @Component
class MyHealthIndicator : HealthIndicator { class MyHealthIndicator : HealthIndicator {
override fun health(): Health { override fun health(): Health {
val errorCode = check() val errorCode = check()
return if (errorCode != 0) { if (errorCode != 0) {
Health.down().withDetail("Error Code", errorCode).build() return Health.down().withDetail("Error Code", errorCode).build()
} else Health.up().build() }
return Health.up().build()
} }
private fun check(): Int { private fun check(): Int {
// perform some specific health check // perform some specific health check
return /**/0 return /**/ 0
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,16 +21,20 @@ import org.springframework.boot.actuate.endpoint.annotation.ReadOperation
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation import org.springframework.boot.actuate.endpoint.annotation.WriteOperation
@Endpoint(id = "custom") @Endpoint(id = "custom")
@Suppress("UNUSED_PARAMETER")
class MyEndpoint { class MyEndpoint {
// tag::read[]
@get:ReadOperation
val data: CustomData
get() = CustomData("test", 5)
// tag::read[]
@ReadOperation
fun getData(): CustomData {
return CustomData("test", 5)
}
// end::read[] // end::read[]
// tag::write[] // tag::write[]
@WriteOperation @WriteOperation
fun updateData(name: String?, counter: Int) { fun updateData(name: String?, counter: Int) {
// injects "test" and 42 // injects "test" and 42
} // end::write[] }
// end::write[]
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,11 +19,13 @@ package org.springframework.boot.docs.actuator.endpoints.info.writingcustominfoc
import org.springframework.boot.actuate.info.Info import org.springframework.boot.actuate.info.Info
import org.springframework.boot.actuate.info.InfoContributor import org.springframework.boot.actuate.info.InfoContributor
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
import java.util.* import java.util.Collections
@Component @Component
class MyInfoContributor : InfoContributor { class MyInfoContributor : InfoContributor {
override fun contribute(builder: Info.Builder) { override fun contribute(builder: Info.Builder) {
builder.withDetail("example", Collections.singletonMap("key", "value")) builder.withDetail("example", Collections.singletonMap("key", "value"))
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,18 +20,16 @@ import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointR
import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Configuration
import org.springframework.security.config.annotation.web.builders.HttpSecurity import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry
import org.springframework.security.web.SecurityFilterChain import org.springframework.security.web.SecurityFilterChain
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class MySecurityConfiguration { class MySecurityConfiguration {
@Bean @Bean
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain { fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
http.requestMatcher(EndpointRequest.toAnyEndpoint()) http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests {
.authorizeRequests { requests: ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry -> requests -> requests.anyRequest().permitAll() }
requests.anyRequest().permitAll()
}
return http.build() return http.build()
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,19 +20,18 @@ import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointR
import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Configuration
import org.springframework.security.config.annotation.web.builders.HttpSecurity import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry
import org.springframework.security.web.SecurityFilterChain import org.springframework.security.web.SecurityFilterChain
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class MySecurityConfiguration { class MySecurityConfiguration {
@Bean @Bean
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain { fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
http.requestMatcher(EndpointRequest.toAnyEndpoint()) http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests { requests ->
.authorizeRequests { requests: ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry -> requests.anyRequest().hasRole("ENDPOINT_ADMIN")
requests.anyRequest().hasRole("ENDPOINT_ADMIN") }
}
http.httpBasic() http.httpBasic()
return http.build() return http.build()
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,8 +22,10 @@ import org.springframework.context.annotation.Configuration
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class MyMetricsFilterConfiguration { class MyMetricsFilterConfiguration {
@Bean @Bean
fun renameRegionTagMeterFilter(): MeterFilter { fun renameRegionTagMeterFilter(): MeterFilter {
return MeterFilter.renameTag("com.example", "mytag.region", "mytag.area") return MeterFilter.renameTag("com.example", "mytag.region", "mytag.area")
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -27,18 +27,13 @@ import org.springframework.context.annotation.Configuration
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class MyGraphiteConfiguration { class MyGraphiteConfiguration {
@Bean @Bean
fun graphiteMeterRegistry(config: GraphiteConfig, clock: Clock): GraphiteMeterRegistry { fun graphiteMeterRegistry(config: GraphiteConfig, clock: Clock): GraphiteMeterRegistry {
return GraphiteMeterRegistry(config, clock, return GraphiteMeterRegistry(config, clock, this::toHierarchicalName)
HierarchicalNameMapper { id: Meter.Id, convention: NamingConvention ->
toHierarchicalName(
id,
convention
)
})
} }
private fun toHierarchicalName(id: Meter.Id, convention: NamingConvention): String { private fun toHierarchicalName(id: Meter.Id, convention: NamingConvention): String {
return /**/HierarchicalNameMapper.DEFAULT.toHierarchicalName(id, convention) return /**/ HierarchicalNameMapper.DEFAULT.toHierarchicalName(id, convention)
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -27,18 +27,14 @@ import org.springframework.context.annotation.Configuration
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class MyJmxConfiguration { class MyJmxConfiguration {
@Bean @Bean
fun jmxMeterRegistry(config: JmxConfig, clock: Clock): JmxMeterRegistry { fun jmxMeterRegistry(config: JmxConfig, clock: Clock): JmxMeterRegistry {
return JmxMeterRegistry(config, clock, return JmxMeterRegistry(config, clock, this::toHierarchicalName)
HierarchicalNameMapper { id: Meter.Id, convention: NamingConvention ->
toHierarchicalName(
id,
convention
)
})
} }
private fun toHierarchicalName(id: Meter.Id, convention: NamingConvention): String { private fun toHierarchicalName(id: Meter.Id, convention: NamingConvention): String {
return /**/HierarchicalNameMapper.DEFAULT.toHierarchicalName(id, convention) return /**/ HierarchicalNameMapper.DEFAULT.toHierarchicalName(id, convention)
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,10 +23,12 @@ import org.springframework.context.annotation.Configuration
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class MyMeterRegistryConfiguration { class MyMeterRegistryConfiguration {
@Bean @Bean
fun metricsCommonTags(): MeterRegistryCustomizer<MeterRegistry> { fun metricsCommonTags(): MeterRegistryCustomizer<MeterRegistry> {
return MeterRegistryCustomizer { registry: MeterRegistry -> return MeterRegistryCustomizer { registry ->
registry.config().commonTags("region", "us-east-1") registry.config().commonTags("region", "us-east-1")
} }
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,21 +25,16 @@ import org.springframework.context.annotation.Configuration
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class MyMeterRegistryConfiguration { class MyMeterRegistryConfiguration {
@Bean @Bean
fun graphiteMetricsNamingConvention(): MeterRegistryCustomizer<GraphiteMeterRegistry> { fun graphiteMetricsNamingConvention(): MeterRegistryCustomizer<GraphiteMeterRegistry> {
return MeterRegistryCustomizer { registry: GraphiteMeterRegistry -> return MeterRegistryCustomizer { registry: GraphiteMeterRegistry ->
registry.config().namingConvention( registry.config().namingConvention(this::name)
NamingConvention { name: String?, type: Meter.Type?, baseUnit: String? ->
name(
name!!,
type!!,
baseUnit
)
})
} }
} }
private fun name(name: String, type: Meter.Type, baseUnit: String?): String { private fun name(name: String, type: Meter.Type, baseUnit: String?): String {
return /**/NamingConvention.snakeCase.name(name, type, baseUnit) return /**/ NamingConvention.snakeCase.name(name, type, baseUnit)
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,6 +17,7 @@
package org.springframework.boot.docs.actuator.metrics.registeringcustom package org.springframework.boot.docs.actuator.metrics.registeringcustom
internal class Dictionary { internal class Dictionary {
val words: List<String> val words: List<String>
get() = emptyList() get() = emptyList()
@ -25,4 +26,5 @@ internal class Dictionary {
return Dictionary() return Dictionary()
} }
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,10 +22,12 @@ import org.springframework.stereotype.Component
@Component @Component
class MyBean(registry: MeterRegistry) { class MyBean(registry: MeterRegistry) {
private val dictionary: Dictionary private val dictionary: Dictionary
init { init {
dictionary = Dictionary.load() dictionary = Dictionary.load()
registry.gauge("dictionary.size", Tags.empty(), dictionary.words.size) registry.gauge("dictionary.size", Tags.empty(), dictionary.words.size)
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,17 +17,16 @@
package org.springframework.boot.docs.actuator.metrics.registeringcustom package org.springframework.boot.docs.actuator.metrics.registeringcustom
import io.micrometer.core.instrument.Gauge import io.micrometer.core.instrument.Gauge
import io.micrometer.core.instrument.MeterRegistry
import io.micrometer.core.instrument.binder.MeterBinder import io.micrometer.core.instrument.binder.MeterBinder
import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Bean
class MyMeterBinderConfiguration { class MyMeterBinderConfiguration {
@Bean @Bean
fun queueSize(queue: Queue): MeterBinder { fun queueSize(queue: Queue): MeterBinder {
return MeterBinder { registry: MeterRegistry -> return MeterBinder { registry ->
Gauge.builder( Gauge.builder("queueSize", queue::size).register(registry)
"queueSize"
) { queue.size() }.register(registry)
} }
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,7 +17,9 @@
package org.springframework.boot.docs.actuator.metrics.registeringcustom package org.springframework.boot.docs.actuator.metrics.registeringcustom
class Queue { class Queue {
fun size(): Int { fun size(): Int {
return 5 return 5
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,7 +21,9 @@ import io.micrometer.core.instrument.Tag
import io.micrometer.core.instrument.binder.mongodb.MongoCommandTagsProvider import io.micrometer.core.instrument.binder.mongodb.MongoCommandTagsProvider
class CustomCommandTagsProvider : MongoCommandTagsProvider { class CustomCommandTagsProvider : MongoCommandTagsProvider {
override fun commandTags(commandEvent: CommandEvent): Iterable<Tag> { override fun commandTags(commandEvent: CommandEvent): Iterable<Tag> {
return emptyList() return emptyList()
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,7 +21,9 @@ import io.micrometer.core.instrument.Tag
import io.micrometer.core.instrument.binder.mongodb.MongoConnectionPoolTagsProvider import io.micrometer.core.instrument.binder.mongodb.MongoConnectionPoolTagsProvider
class CustomConnectionPoolTagsProvider : MongoConnectionPoolTagsProvider { class CustomConnectionPoolTagsProvider : MongoConnectionPoolTagsProvider {
override fun connectionPoolTags(event: ConnectionPoolCreatedEvent): Iterable<Tag> { override fun connectionPoolTags(event: ConnectionPoolCreatedEvent): Iterable<Tag> {
return emptyList() return emptyList()
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,8 +22,10 @@ import org.springframework.context.annotation.Configuration
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class MyConnectionPoolTagsProviderConfiguration { class MyConnectionPoolTagsProviderConfiguration {
@Bean @Bean
fun customConnectionPoolTagsProvider(): MongoConnectionPoolTagsProvider { fun customConnectionPoolTagsProvider(): MongoConnectionPoolTagsProvider {
return CustomConnectionPoolTagsProvider() return CustomConnectionPoolTagsProvider()
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,5 +16,4 @@
package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.all package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.all
class Address { class Address
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController @RestController
@Timed @Timed
class MyController { class MyController {
@GetMapping("/api/addresses") @GetMapping("/api/addresses")
fun listAddress(): List<Address>? { fun listAddress(): List<Address>? {
return /**/null return /**/null
@ -32,4 +33,5 @@ class MyController {
fun listPeople(): List<Person>? { fun listPeople(): List<Person>? {
return /**/null return /**/null
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,5 +16,4 @@
package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.all package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.all
class Person { class Person
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,5 +16,4 @@
package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.change package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.change
class Address { class Address
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController @RestController
@Timed @Timed
class MyController { class MyController {
@GetMapping("/api/addresses") @GetMapping("/api/addresses")
fun listAddress(): List<Address>? { fun listAddress(): List<Address>? {
return /**/null return /**/null
@ -33,4 +34,5 @@ class MyController {
fun listPeople(): List<Person>? { fun listPeople(): List<Person>? {
return /**/null return /**/null
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,5 +16,4 @@
package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.change package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.change
class Person { class Person
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,5 +16,4 @@
package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.single package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.single
class Address { class Address
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController @RestController
class MyController { class MyController {
@GetMapping("/api/addresses") @GetMapping("/api/addresses")
fun listAddress(): List<Address>? { fun listAddress(): List<Address>? {
return /**/null return /**/null
@ -32,4 +33,5 @@ class MyController {
fun listPeople(): List<Person>? { fun listPeople(): List<Person>? {
return /**/null return /**/null
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,5 +16,4 @@
package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.single package org.springframework.boot.docs.actuator.metrics.supported.timedannotation.single
class Person { class Person
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import java.io.IOException
import kotlin.jvm.Throws import kotlin.jvm.Throws
class MyBuildTool { class MyBuildTool {
@Throws(IOException::class) @Throws(IOException::class)
fun build() { fun build() {
val sourceJarFile: File? = /**/null val sourceJarFile: File? = /**/null
@ -36,13 +37,14 @@ class MyBuildTool {
@Throws(IOException::class) @Throws(IOException::class)
private fun getLibraries(callback: LibraryCallback) { private fun getLibraries(callback: LibraryCallback) {
// Build system specific implementation, callback for each dependency // Build system specific implementation, callback for each dependency
for (nestedJar in compileScopeJars!!) { for (nestedJar in getCompileScopeJars()!!) {
callback.library(Library(nestedJar, LibraryScope.COMPILE)) callback.library(Library(nestedJar, LibraryScope.COMPILE))
} }
// ... // ...
} }
/**/ private fun getCompileScopeJars(): List<File?>? {
private val compileScopeJars: List<File>? return /**/ null
get() =/**/null }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,11 +17,13 @@
package org.springframework.boot.docs.configurationmetadata.annotationprocessor.automaticmetadatageneration package org.springframework.boot.docs.configurationmetadata.annotationprocessor.automaticmetadatageneration
import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.boot.context.properties.ConfigurationProperties
import java.util.* import java.util.Arrays
@ConfigurationProperties(prefix = "my.messaging") @ConfigurationProperties(prefix = "my.messaging")
class MyMessagingProperties( class MyMessagingProperties(
val addresses: List<String> = ArrayList(Arrays.asList("a", "b")), val addresses: List<String> = ArrayList(Arrays.asList("a", "b")),
var containerType: ContainerType = ContainerType.SIMPLE) { var containerType: ContainerType = ContainerType.SIMPLE) {
enum class ContainerType { enum class ContainerType {

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,16 +20,18 @@ import org.springframework.boot.context.properties.ConfigurationProperties
@ConfigurationProperties(prefix = "my.server") @ConfigurationProperties(prefix = "my.server")
class MyServerProperties( class MyServerProperties(
/** /**
* Name of the server. * Name of the server.
*/ */
var name: String, var name: String,
/** /**
* IP address to listen to. * IP address to listen to.
*/ */
var ip: String = "127.0.0.1", var ip: String = "127.0.0.1",
/** /**
* Port to listen to. * Port to listen to.
*/ */
var port: Int = 9797) { var port: Int = 9797)
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,4 +24,5 @@ class MyServerProperties(
var host: Host) { var host: Host) {
class Host(val ip: String, val port: Int = 0) class Host(val ip: String, val port: Int = 0)
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -14,14 +14,16 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.docs.configurationmetadata.format.group package org.springframework.boot.docs.configurationmetadata.format.property
import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty import org.springframework.boot.context.properties.DeprecatedConfigurationProperty
@ConfigurationProperties("my.app") @ConfigurationProperties("my.app")
class MyProperties(val name: String?) { class MyProperties(val name: String?) {
var target: String? = null var target: String? = null
@Deprecated("") @DeprecatedConfigurationProperty(replacement = "my.app.name") get @Deprecated("") @DeprecatedConfigurationProperty(replacement = "my.app.name") get
@Deprecated("") set @Deprecated("") set
} }

@ -1,7 +1,22 @@
/*
* Copyright 2012-2022 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.configurationmetadata.manualhints.valuehint package org.springframework.boot.docs.configurationmetadata.manualhints.valuehint
import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.boot.context.properties.ConfigurationProperties
@ConfigurationProperties("my") @ConfigurationProperties("my")
class MyProperties(val contexts: Map<String, Int>) { class MyProperties(val contexts: Map<String, Int>)
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,8 +21,11 @@ import org.springframework.stereotype.Component
@Component @Component
class MyBean(private val template: CassandraTemplate) { class MyBean(private val template: CassandraTemplate) {
// @fold:on // ... // @fold:on // ...
fun someMethod(): Long { fun someMethod(): Long {
return template.count(User::class.java) return template.count(User::class.java)
} // @fold:off }
// @fold:off
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,5 +16,4 @@
package org.springframework.boot.docs.data.nosql.couchbase.repositories package org.springframework.boot.docs.data.nosql.couchbase.repositories
class CouchbaseProperties { class CouchbaseProperties
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,8 +21,11 @@ import org.springframework.stereotype.Component
@Component @Component
class MyBean(private val template: CouchbaseTemplate) { class MyBean(private val template: CouchbaseTemplate) {
// @fold:on // ... // @fold:on // ...
fun someMethod(): String { fun someMethod(): String {
return template.bucketName return template.bucketName
} // @fold:off }
// @fold:off
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,9 +18,10 @@ package org.springframework.boot.docs.data.nosql.couchbase.repositories
import org.springframework.core.convert.converter.Converter import org.springframework.core.convert.converter.Converter
internal class MyConverter : internal class MyConverter : Converter<CouchbaseProperties?, Boolean> {
Converter<CouchbaseProperties?, Boolean> {
override fun convert(value: CouchbaseProperties?): Boolean { override fun convert(value: CouchbaseProperties?): Boolean {
return true return true
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,8 +24,10 @@ import org.springframework.data.couchbase.core.convert.CouchbaseCustomConversion
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class MyCouchbaseConfiguration { class MyCouchbaseConfiguration {
@Bean(BeanNames.COUCHBASE_CUSTOM_CONVERSIONS) @Bean(BeanNames.COUCHBASE_CUSTOM_CONVERSIONS)
fun myCustomConversions(): CouchbaseCustomConversions { fun myCustomConversions(): CouchbaseCustomConversions {
return CouchbaseCustomConversions(Arrays.asList(MyConverter())) return CouchbaseCustomConversions(Arrays.asList(MyConverter()))
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,8 +21,11 @@ import org.springframework.stereotype.Component
@Component @Component
class MyBean(private val template: ElasticsearchRestTemplate) { class MyBean(private val template: ElasticsearchRestTemplate) {
// @fold:on // ... // @fold:on // ...
fun someMethod(id: String): Boolean { fun someMethod(id: String): Boolean {
return template.exists(id, User::class.java) return template.exists(id, User::class.java)
} // @fold:off }
// @fold:off
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,5 +16,4 @@
package org.springframework.boot.docs.data.nosql.elasticsearch.connectingusingspringdata package org.springframework.boot.docs.data.nosql.elasticsearch.connectingusingspringdata
class User { class User
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,8 +21,11 @@ import org.springframework.stereotype.Component
@Component @Component
class MyBean(private val template: LdapTemplate) { class MyBean(private val template: LdapTemplate) {
// @fold:on // ... // @fold:on // ...
fun someMethod(): List<User> { fun someMethod(): List<User> {
return template.findAll(User::class.java) return template.findAll(User::class.java)
} // @fold:off }
// @fold:off
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,5 +16,4 @@
package org.springframework.boot.docs.data.nosql.ldap.repositories package org.springframework.boot.docs.data.nosql.ldap.repositories
class User { class User
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,9 +23,12 @@ import org.springframework.stereotype.Component
@Component @Component
class MyBean(private val mongo: MongoDatabaseFactory) { class MyBean(private val mongo: MongoDatabaseFactory) {
// @fold:on // ... // @fold:on // ...
fun someMethod(): MongoCollection<Document> { fun someMethod(): MongoCollection<Document> {
val db = mongo.mongoDatabase val db = mongo.mongoDatabase
return db.getCollection("users") return db.getCollection("users")
} // @fold:off }
// @fold:off
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,5 +16,4 @@
package org.springframework.boot.docs.data.nosql.mongodb.repositories package org.springframework.boot.docs.data.nosql.mongodb.repositories
class City { class City
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,8 +23,11 @@ import org.springframework.stereotype.Component
@Component @Component
class MyBean(private val mongoTemplate: MongoTemplate) { class MyBean(private val mongoTemplate: MongoTemplate) {
// @fold:on // ... // @fold:on // ...
fun someMethod(): MongoCollection<Document> { fun someMethod(): MongoCollection<Document> {
return mongoTemplate.getCollection("users") return mongoTemplate.getCollection("users")
} // @fold:off }
// @fold:off
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,14 +26,13 @@ class MyBean(private val driver: Driver) {
// @fold:on // ... // @fold:on // ...
fun someMethod(message: String?): String { fun someMethod(message: String?): String {
driver.session().use { session -> driver.session().use { session ->
return session.writeTransaction { transaction: Transaction -> return@someMethod session.writeTransaction { transaction: Transaction ->
transaction transaction.run(
.run( "CREATE (a:Greeting) SET a.message = \$message RETURN a.message + ', from node ' + id(a)",
"CREATE (a:Greeting) SET a.message = \$message RETURN a.message + ', from node ' + id(a)", Values.parameters("message", message)
Values.parameters("message", message) ).single()[0].asString()
)
.single()[0].asString()
} }
} }
} // @fold:off }
// @fold:off
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,5 +16,4 @@
package org.springframework.boot.docs.data.nosql.neo4j.repositories package org.springframework.boot.docs.data.nosql.neo4j.repositories
class City { class City
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,9 +17,10 @@
package org.springframework.boot.docs.data.nosql.neo4j.repositories package org.springframework.boot.docs.data.nosql.neo4j.repositories
import org.springframework.data.neo4j.repository.Neo4jRepository import org.springframework.data.neo4j.repository.Neo4jRepository
import java.util.* import java.util.Optional
interface CityRepository : Neo4jRepository<City?, Long?> {
interface CityRepository :
Neo4jRepository<City?, Long?> {
fun findOneByNameAndState(name: String?, state: String?): Optional<City?>? fun findOneByNameAndState(name: String?, state: String?): Optional<City?>?
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,11 +24,10 @@ import org.springframework.data.neo4j.core.transaction.ReactiveNeo4jTransactionM
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class MyNeo4jConfiguration { class MyNeo4jConfiguration {
@Bean @Bean
fun reactiveTransactionManager( fun reactiveTransactionManager(driver: Driver,
driver: Driver, databaseNameProvider: ReactiveDatabaseSelectionProvider): ReactiveNeo4jTransactionManager {
databaseNameProvider: ReactiveDatabaseSelectionProvider
): ReactiveNeo4jTransactionManager {
return ReactiveNeo4jTransactionManager(driver, databaseNameProvider) return ReactiveNeo4jTransactionManager(driver, databaseNameProvider)
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,8 +21,11 @@ import org.springframework.stereotype.Component
@Component @Component
class MyBean(private val template: StringRedisTemplate) { class MyBean(private val template: StringRedisTemplate) {
// @fold:on // ... // @fold:on // ...
fun someMethod(): Boolean { fun someMethod(): Boolean {
return template.hasKey("spring") return template.hasKey("spring")
} // @fold:off }
// @fold:off
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,11 +20,13 @@ import org.apache.solr.client.solrj.SolrClient
import org.apache.solr.client.solrj.response.SolrPingResponse import org.apache.solr.client.solrj.response.SolrPingResponse
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
@Component @Component
class MyBean(private val solr: SolrClient) { class MyBean(private val solr: SolrClient) {
// @fold:on // ... // @fold:on // ...
fun someMethod(): SolrPingResponse { fun someMethod(): SolrPingResponse {
return solr.ping("users") return solr.ping("users")
} // @fold:off }
// @fold:off
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,7 +21,9 @@ import org.springframework.stereotype.Component
@Component @Component
class MyBean(private val jdbcTemplate: JdbcTemplate) { class MyBean(private val jdbcTemplate: JdbcTemplate) {
fun doSomething() { fun doSomething() {
jdbcTemplate.execute("delete from customer") jdbcTemplate.execute("delete from customer")
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,16 +18,17 @@ package org.springframework.boot.docs.data.sql.jooq.dslcontext
import org.jooq.DSLContext import org.jooq.DSLContext
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
import java.util.* import java.util.GregorianCalendar
@Component @Component
class MyBean(private val create: DSLContext) { class MyBean(private val create: DSLContext) {
// tag::method[] // tag::method[]
fun authorsBornAfter1980(): List<GregorianCalendar> { fun authorsBornAfter1980(): List<GregorianCalendar> {
// @formatter:off
return create.selectFrom<Tables.TAuthorRecord>(Tables.AUTHOR) return create.selectFrom<Tables.TAuthorRecord>(Tables.AUTHOR)
.where(Tables.AUTHOR?.DATE_OF_BIRTH?.greaterThan(GregorianCalendar(1980, 0, 1))) .where(Tables.AUTHOR?.DATE_OF_BIRTH?.greaterThan(GregorianCalendar(1980, 0, 1)))
.fetch(Tables.AUTHOR?.DATE_OF_BIRTH) .fetch(Tables.AUTHOR?.DATE_OF_BIRTH)
// @formatter:on }
} // end::method[] // end::method[]
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,15 +21,16 @@ import org.jooq.Table
import org.jooq.TableField import org.jooq.TableField
import org.jooq.impl.TableImpl import org.jooq.impl.TableImpl
import org.jooq.impl.TableRecordImpl import org.jooq.impl.TableRecordImpl
import java.util.* import java.util.GregorianCalendar
object Tables { object Tables {
val AUTHOR: TAuthor? = null val AUTHOR: TAuthor? = null
abstract class TAuthor(name: Name?) : TableImpl<TAuthorRecord?>(name) { abstract class TAuthor(name: Name?) : TableImpl<TAuthorRecord?>(name) {
val DATE_OF_BIRTH: TableField<TAuthorRecord, GregorianCalendar>? = null val DATE_OF_BIRTH: TableField<TAuthorRecord, GregorianCalendar>? = null
} }
abstract class TAuthorRecord(table: Table<TAuthorRecord?>?) : abstract class TAuthorRecord(table: Table<TAuthorRecord?>?) : TableRecordImpl<TAuthorRecord?>(table)
TableRecordImpl<TAuthorRecord?>(table)
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,6 +24,7 @@ import javax.persistence.Id
@Entity @Entity
class City : Serializable { class City : Serializable {
@Id @Id
@GeneratedValue @GeneratedValue
private val id: Long? = null private val id: Long? = null
@ -48,4 +49,5 @@ class City : Serializable {
this.name = name this.name = name
this.state = state this.state = state
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import javax.persistence.Id
@Entity @Entity
class Country : Serializable { class Country : Serializable {
@Id @Id
@GeneratedValue @GeneratedValue
var id: Long? = null var id: Long? = null
@ -32,4 +33,5 @@ class Country : Serializable {
@Audited @Audited
@Column(nullable = false) @Column(nullable = false)
var name: String? = null var name: String? = null
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.docs.data.sql.jpaandspringdata.repositories package org.springframework.boot.docs.data.sql.jpaandspringdata.enversrepositories
import org.springframework.boot.docs.data.sql.jpaandspringdata.entityclasses.Country import org.springframework.boot.docs.data.sql.jpaandspringdata.entityclasses.Country
import org.springframework.data.domain.Page import org.springframework.data.domain.Page
@ -23,7 +23,9 @@ import org.springframework.data.repository.Repository
import org.springframework.data.repository.history.RevisionRepository import org.springframework.data.repository.history.RevisionRepository
interface CountryRepository : interface CountryRepository :
RevisionRepository<Country?, Long?, Int>, RevisionRepository<Country?, Long?, Int>,
Repository<Country?, Long?> { Repository<Country?, Long?> {
fun findAll(pageable: Pageable?): Page<Country?>? fun findAll(pageable: Pageable?): Page<Country?>?
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,8 +21,10 @@ import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable import org.springframework.data.domain.Pageable
import org.springframework.data.repository.Repository import org.springframework.data.repository.Repository
interface CityRepository : interface CityRepository : Repository<City?, Long?> {
Repository<City?, Long?> {
fun findAll(pageable: Pageable?): Page<City?>? fun findAll(pageable: Pageable?): Page<City?>?
fun findByNameAndStateAllIgnoringCase(name: String?, state: String?): City? fun findByNameAndStateAllIgnoringCase(name: String?, state: String?): City?
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,23 +17,21 @@
package org.springframework.boot.docs.data.sql.r2dbc package org.springframework.boot.docs.data.sql.r2dbc
import io.r2dbc.postgresql.PostgresqlConnectionFactoryProvider import io.r2dbc.postgresql.PostgresqlConnectionFactoryProvider
import io.r2dbc.spi.ConnectionFactoryOptions
import org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryOptionsBuilderCustomizer import org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryOptionsBuilderCustomizer
import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Configuration
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class MyPostgresR2dbcConfiguration { class MyPostgresR2dbcConfiguration {
@Bean @Bean
fun postgresCustomizer(): ConnectionFactoryOptionsBuilderCustomizer { fun postgresCustomizer(): ConnectionFactoryOptionsBuilderCustomizer {
val options: MutableMap<String, String> = HashMap() val options: MutableMap<String, String> = HashMap()
options["lock_timeout"] = "30s" options["lock_timeout"] = "30s"
options["statement_timeout"] = "60s" options["statement_timeout"] = "60s"
return ConnectionFactoryOptionsBuilderCustomizer { builder: ConnectionFactoryOptions.Builder -> return ConnectionFactoryOptionsBuilderCustomizer { builder ->
builder.option( builder.option(PostgresqlConnectionFactoryProvider.OPTIONS, options)
PostgresqlConnectionFactoryProvider.OPTIONS,
options
)
} }
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,13 +23,12 @@ import org.springframework.context.annotation.Configuration
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class MyR2dbcConfiguration { class MyR2dbcConfiguration {
@Bean @Bean
fun connectionFactoryPortCustomizer(): ConnectionFactoryOptionsBuilderCustomizer { fun connectionFactoryPortCustomizer(): ConnectionFactoryOptionsBuilderCustomizer {
return ConnectionFactoryOptionsBuilderCustomizer { builder: ConnectionFactoryOptions.Builder -> return ConnectionFactoryOptionsBuilderCustomizer { builder ->
builder.option( builder.option(ConnectionFactoryOptions.PORT, 5432)
ConnectionFactoryOptions.PORT,
5432
)
} }
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,5 +16,4 @@
package org.springframework.boot.docs.data.sql.r2dbc.repositories package org.springframework.boot.docs.data.sql.r2dbc.repositories
class City { class City
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,7 +19,8 @@ package org.springframework.boot.docs.data.sql.r2dbc.repositories
import org.springframework.data.repository.Repository import org.springframework.data.repository.Repository
import reactor.core.publisher.Mono import reactor.core.publisher.Mono
interface CityRepository : interface CityRepository : Repository<City?, Long?> {
Repository<City?, Long?> {
fun findByNameAndStateAllIgnoringCase(name: String?, state: String?): Mono<City?>? fun findByNameAndStateAllIgnoringCase(name: String?, state: String?): Mono<City?>?
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,8 +22,11 @@ import reactor.core.publisher.Flux
@Component @Component
class MyBean(private val databaseClient: DatabaseClient) { class MyBean(private val databaseClient: DatabaseClient) {
// @fold:on // ... // @fold:on // ...
fun someMethod(): Flux<Map<String, Any>> { fun someMethod(): Flux<Map<String, Any>> {
return databaseClient.sql("select * from user").fetch().all() return databaseClient.sql("select * from user").fetch().all()
} // @fold:off }
// @fold:off
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,10 +22,13 @@ import org.springframework.stereotype.Component
@Component @Component
class MyBean : EnvironmentAware { class MyBean : EnvironmentAware {
private var instanceId: String? = null private var instanceId: String? = null
override fun setEnvironment(environment: Environment) { override fun setEnvironment(environment: Environment) {
instanceId = environment.getProperty("vcap.application.instance_id") instanceId = environment.getProperty("vcap.application.instance_id")
} }
// ... // ...
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,9 +22,11 @@ import org.springframework.context.annotation.Configuration
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class MyAutoConfiguration { class MyAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
fun someService(): SomeService { fun someService(): SomeService {
return SomeService() return SomeService()
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,14 +24,18 @@ import org.springframework.context.annotation.Configuration
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
// Some conditions ... // Some conditions ...
class MyAutoConfiguration { class MyAutoConfiguration {
// Auto-configured beans ... // Auto-configured beans ...
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnClass(SomeService::class) @ConditionalOnClass(SomeService::class)
class SomeServiceConfiguration { class SomeServiceConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
fun someService(): SomeService { fun someService(): SomeService {
return SomeService() return SomeService()
} }
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import java.time.Duration
@ConfigurationProperties("acme") @ConfigurationProperties("acme")
class AcmeProperties( class AcmeProperties(
/** /**
* Whether to check the location of acme resources. * Whether to check the location of acme resources.
*/ */

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,13 +22,14 @@ import org.springframework.boot.logging.LogLevel
import org.springframework.boot.test.context.assertj.AssertableApplicationContext import org.springframework.boot.test.context.assertj.AssertableApplicationContext
import org.springframework.boot.test.context.runner.ApplicationContextRunner import org.springframework.boot.test.context.runner.ApplicationContextRunner
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
class MyConditionEvaluationReportingTests { class MyConditionEvaluationReportingTests {
@Test @Test
fun autoConfigTest() { fun autoConfigTest() {
// @formatter:off
ApplicationContextRunner() ApplicationContextRunner()
.withInitializer(ConditionEvaluationReportLoggingListener(LogLevel.INFO)) .withInitializer(ConditionEvaluationReportLoggingListener(LogLevel.INFO))
.run { context: AssertableApplicationContext? -> } .run { context: AssertableApplicationContext? -> }
// @formatter:on
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ import org.springframework.context.annotation.Configuration
UserProperties::class UserProperties::class
) )
class MyServiceAutoConfiguration { class MyServiceAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
fun userService(properties: UserProperties): MyService { fun userService(properties: UserProperties): MyService {
@ -40,4 +41,5 @@ class MyServiceAutoConfiguration {
class UserProperties { class UserProperties {
var name = "test" var name = "test"
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,7 @@
package org.springframework.boot.docs.features.developingautoconfiguration.testing package org.springframework.boot.docs.features.developingautoconfiguration.testing
import org.assertj.core.api.Assertions import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.boot.autoconfigure.AutoConfigurations import org.springframework.boot.autoconfigure.AutoConfigurations
import org.springframework.boot.test.context.FilteredClassLoader import org.springframework.boot.test.context.FilteredClassLoader
@ -25,67 +25,53 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner
import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Configuration
internal open class MyServiceAutoConfigurationTests { internal open class MyServiceAutoConfigurationTests {
// tag::runner[] // tag::runner[]
val contextRunner = ApplicationContextRunner() val contextRunner = ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(MyServiceAutoConfiguration::class.java)) .withConfiguration(AutoConfigurations.of(MyServiceAutoConfiguration::class.java))
// end::runner[] // end::runner[]
// tag::test-env[] // tag::test-env[]
@Test @Test
fun serviceNameCanBeConfigured() { fun serviceNameCanBeConfigured() {
contextRunner.withPropertyValues("user.name=test123").run { context: AssertableApplicationContext -> contextRunner.withPropertyValues("user.name=test123").run { context: AssertableApplicationContext ->
Assertions.assertThat(context) assertThat(context).hasSingleBean(MyService::class.java)
.hasSingleBean( assertThat(context.getBean(MyService::class.java).name).isEqualTo("test123")
MyService::class.java
)
Assertions.assertThat(
context.getBean(
MyService::class.java
).name
).isEqualTo("test123")
} }
} }
// end::test-env[] // end::test-env[]
// tag::test-classloader[] // tag::test-classloader[]
@Test @Test
fun serviceIsIgnoredIfLibraryIsNotPresent() { fun serviceIsIgnoredIfLibraryIsNotPresent() {
contextRunner.withClassLoader(FilteredClassLoader(MyService::class.java)) contextRunner.withClassLoader(FilteredClassLoader(MyService::class.java))
.run { context: AssertableApplicationContext? -> .run { context: AssertableApplicationContext? ->
Assertions.assertThat( assertThat(context).doesNotHaveBean("myService")
context
).doesNotHaveBean("myService")
} }
} }
// end::test-classloader[] // end::test-classloader[]
// tag::test-user-config[] // tag::test-user-config[]
@Test @Test
fun defaultServiceBacksOff() { fun defaultServiceBacksOff() {
contextRunner.withUserConfiguration(UserConfiguration::class.java) contextRunner.withUserConfiguration(UserConfiguration::class.java)
.run { context: AssertableApplicationContext -> .run { context: AssertableApplicationContext ->
Assertions.assertThat( assertThat(context).hasSingleBean(MyService::class.java)
context assertThat(context).getBean("myCustomService")
).hasSingleBean( .isSameAs(context.getBean(MyService::class.java))
MyService::class.java
)
Assertions.assertThat(
context
).getBean("myCustomService").isSameAs(
context.getBean(
MyService::class.java
)
)
} }
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
internal class UserConfiguration { internal class UserConfiguration {
@Bean @Bean
fun myCustomService(): MyService { fun myCustomService(): MyService {
return MyService("mine") return MyService("mine")
} }
} // end::test-user-config[]
}
// end::test-user-config[]
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,8 +21,10 @@ import org.springframework.stereotype.Component
@Component @Component
class MyBean { class MyBean {
@Value("\${name}") @Value("\${name}")
private val name: String? = null private val name: String? = null
// ... // ...
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,10 +23,10 @@ import java.net.InetAddress
@ConstructorBinding @ConstructorBinding
@ConfigurationProperties("my.service") @ConfigurationProperties("my.service")
class MyProperties(val enabled: Boolean, val remoteAddress: InetAddress, val security: Security) { class MyProperties(val enabled: Boolean, val remoteAddress: InetAddress,
val security: Security) {
class Security(val username: String, val password: String,
@param:DefaultValue("USER") val roles: List<String>)
class Security(
val username: String, val password: String,
@param:DefaultValue("USER") val roles: List<String>
)
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,12 +23,10 @@ import java.net.InetAddress
@ConstructorBinding @ConstructorBinding
@ConfigurationProperties("my.service") @ConfigurationProperties("my.service")
class MyProperties( class MyProperties(val isEnabled: Boolean, val remoteAddress: InetAddress,
val isEnabled: Boolean, val remoteAddress: InetAddress, @param:DefaultValue val security: Security @param:DefaultValue val security: Security) {
) {
class Security(val username: String, val password: String,
@param:DefaultValue("USER") val roles: List<String>)
class Security(
val username: String, val password: String,
@param:DefaultValue("USER") val roles: List<String>
)
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,8 +25,5 @@ import org.springframework.util.unit.DataUnit
@ConfigurationProperties("my") @ConfigurationProperties("my")
@ConstructorBinding @ConstructorBinding
class MyProperties( class MyProperties(@param:DataSizeUnit(DataUnit.MEGABYTES) @param:DefaultValue("2MB") val bufferSize: DataSize,
@param:DataSizeUnit(DataUnit.MEGABYTES) @param:DefaultValue("2MB") @param:DefaultValue("512B") val sizeThreshold: DataSize)
val bufferSize: DataSize,
@param:DefaultValue("512B") val sizeThreshold: DataSize
)

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,8 +23,10 @@ import org.springframework.util.unit.DataUnit
@ConfigurationProperties("my") @ConfigurationProperties("my")
class MyProperties { class MyProperties {
@DataSizeUnit(DataUnit.MEGABYTES) @DataSizeUnit(DataUnit.MEGABYTES)
var bufferSize = DataSize.ofMegabytes(2) var bufferSize = DataSize.ofMegabytes(2)
var sizeThreshold = DataSize.ofBytes(512) var sizeThreshold = DataSize.ofBytes(512)
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -25,7 +25,5 @@ import java.time.temporal.ChronoUnit
@ConfigurationProperties("my") @ConfigurationProperties("my")
@ConstructorBinding @ConstructorBinding
class MyProperties( class MyProperties(@param:DurationUnit(ChronoUnit.SECONDS) @param:DefaultValue("30s") val sessionTimeout: Duration,
@param:DurationUnit(ChronoUnit.SECONDS) @param:DefaultValue("30s") val sessionTimeout: Duration, @param:DefaultValue("1000ms") val readTimeout: Duration)
@param:DefaultValue("1000ms") val readTimeout: Duration
)

@ -1,3 +1,19 @@
/*
* Copyright 2012-2022 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.features.externalconfig.typesafeconfigurationproperties.conversion.durations.javabeanbinding package org.springframework.boot.docs.features.externalconfig.typesafeconfigurationproperties.conversion.durations.javabeanbinding
import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.boot.context.properties.ConfigurationProperties
@ -7,8 +23,10 @@ import java.time.temporal.ChronoUnit
@ConfigurationProperties("my") @ConfigurationProperties("my")
class MyProperties { class MyProperties {
@DurationUnit(ChronoUnit.SECONDS) @DurationUnit(ChronoUnit.SECONDS)
var sessionTimeout = Duration.ofSeconds(30) var sessionTimeout = Duration.ofSeconds(30)
var readTimeout = Duration.ofMillis(1000) var readTimeout = Duration.ofMillis(1000)
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -21,14 +21,21 @@ import java.net.InetAddress
@ConfigurationProperties("my.service") @ConfigurationProperties("my.service")
class MyProperties { class MyProperties {
var isEnabled = false var isEnabled = false
var remoteAddress: InetAddress? = null var remoteAddress: InetAddress? = null
val security = Security() val security = Security()
class Security { class Security {
var username: String? = null var username: String? = null
var password: String? = null var password: String? = null
var roles: List<String> = ArrayList(setOf("USER")) var roles: List<String> = ArrayList(setOf("USER"))
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,5 +16,4 @@
package org.springframework.boot.docs.features.externalconfig.typesafeconfigurationproperties.mergingcomplextypes.list package org.springframework.boot.docs.features.externalconfig.typesafeconfigurationproperties.mergingcomplextypes.list
class MyPojo { class MyPojo
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,5 +20,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties
@ConfigurationProperties("my") @ConfigurationProperties("my")
class MyProperties { class MyProperties {
val list: List<MyPojo> = ArrayList() val list: List<MyPojo> = ArrayList()
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,5 +16,4 @@
package org.springframework.boot.docs.features.externalconfig.typesafeconfigurationproperties.mergingcomplextypes.map package org.springframework.boot.docs.features.externalconfig.typesafeconfigurationproperties.mergingcomplextypes.map
class MyPojo { class MyPojo
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,5 +20,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties
@ConfigurationProperties("my") @ConfigurationProperties("my")
class MyProperties { class MyProperties {
val map: Map<String, MyPojo> = LinkedHashMap() val map: Map<String, MyPojo> = LinkedHashMap()
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,5 +20,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties
@ConfigurationProperties(prefix = "my.main-project.person") @ConfigurationProperties(prefix = "my.main-project.person")
class MyPersonProperties { class MyPersonProperties {
var firstName: String? = null var firstName: String? = null
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,5 +16,4 @@
package org.springframework.boot.docs.features.externalconfig.typesafeconfigurationproperties.thirdpartyconfiguration package org.springframework.boot.docs.features.externalconfig.typesafeconfigurationproperties.thirdpartyconfiguration
class AnotherComponent { class AnotherComponent
}

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,7 +22,9 @@ import org.springframework.context.annotation.Configuration
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
class ThirdPartyConfiguration { class ThirdPartyConfiguration {
@Bean @Bean
@ConfigurationProperties(prefix = "another") @ConfigurationProperties(prefix = "another")
fun anotherComponent(): AnotherComponent = AnotherComponent() fun anotherComponent(): AnotherComponent = AnotherComponent()
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,6 +20,7 @@ import org.springframework.stereotype.Service
@Service @Service
class MyService(val properties: SomeProperties) { class MyService(val properties: SomeProperties) {
fun openConnection() { fun openConnection() {
val server = Server(properties.remoteAddress) val server = Server(properties.remoteAddress)
server.start() server.start()
@ -27,4 +28,5 @@ class MyService(val properties: SomeProperties) {
} }
// ... // ...
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,9 +13,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.docs.features.externalconfig.typesafeconfigurationproperties.usingannotatedtypes package org.springframework.boot.docs.features.externalconfig.typesafeconfigurationproperties.usingannotatedtypes
class SomeProperties { class SomeProperties {
val remoteAddress: Any? val remoteAddress: Any?
get() = null get() = null
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,5 +24,7 @@ import javax.validation.constraints.NotNull
@ConfigurationProperties("my.service") @ConfigurationProperties("my.service")
@Validated @Validated
class MyProperties { class MyProperties {
var remoteAddress: @NotNull InetAddress? = null var remoteAddress: @NotNull InetAddress? = null
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2021 the original author or authors. * Copyright 2012-2022 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,10 +26,13 @@ import javax.validation.constraints.NotNull
@ConfigurationProperties("my.service") @ConfigurationProperties("my.service")
@Validated @Validated
class MyProperties { class MyProperties {
var remoteAddress: @NotNull InetAddress? = null var remoteAddress: @NotNull InetAddress? = null
val security: @Valid Security? = Security() val security: @Valid Security? = Security()
class Security { class Security {
var username: @NotEmpty String? = null var username: @NotEmpty String? = null
} }
} }

@ -0,0 +1,30 @@
/*
* Copyright 2012-2022 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.features.externalconfig.typesafeconfigurationproperties.validation
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.validation.annotation.Validated
import java.net.InetAddress
import javax.validation.constraints.NotNull
@ConfigurationProperties("my.service")
@Validated
class MyProperties {
var remoteAddress: @NotNull InetAddress? = null
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save