Hullaballoonatic
11/05/2019, 7:05 PM@Configuration
class FooConfiguration {
@Value("\${foo.bar}")
lateinit var bar: String
}
This just seems really verbose, even compared to the java way, and I tend to prefer lazy delegation val over lateinit var for immutable properties like this.Dariusz Kuc
11/05/2019, 7:13 PM@ConstructorBinding
@Configuration("foo")
class FooConfiguration(val bar: String)
Hullaballoonatic
11/05/2019, 8:30 PMDariusz Kuc
11/05/2019, 8:35 PM<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring-boot.version}</version>
<optional>true</optional>
</dependency>
in your deps?Hullaballoonatic
11/05/2019, 8:36 PMimport org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
val kotlinVersion = "1.3.50"
idea
kotlin("jvm") version kotlinVersion
kotlin("plugin.spring") version kotlinVersion
kotlin("kapt") version kotlinVersion
id("org.springframework.boot") version "2.2.0.RELEASE"
id("io.spring.dependency-management") version "1.0.8.RELEASE"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
kapt("org.springframework.boot", "spring-boot-configuration-processor")
implementation("org.springframework.boot", "spring-boot-configuration-processor")
implementation("org.springframework.boot", "spring-boot-starter-web")
implementation("org.springframework.security.oauth.boot", "spring-security-oauth2-autoconfigure", "2.2.0.RELEASE")
implementation("org.springframework.boot", "spring-boot-starter-data-mongodb")
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
Hullaballoonatic
11/05/2019, 8:37 PMDariusz Kuc
11/05/2019, 8:37 PMDariusz Kuc
11/05/2019, 8:38 PMHullaballoonatic
11/05/2019, 8:38 PMHullaballoonatic
11/05/2019, 8:41 PMorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resource-server': @EnableConfigurationProperties or @ConfigurationPropertiesScan must be used to add @ConstructorBinding type src.config.ResourceServerConfiguration
when @EnableConfigurationProperties
is literally right there in the code:
@EnableResourceServer
@EnableConfigurationProperties
@ConstructorBinding
@Configuration("resource-server")
class ResourceServerConfiguration(val resourceId: String) : ResourceServerConfigurerAdapter()
Dariusz Kuc
11/05/2019, 8:43 PM@EnableConfigurationProperties(FooConfiguration::class)
?Dariusz Kuc
11/05/2019, 8:43 PMDariusz Kuc
11/05/2019, 8:45 PM@EnableConfigurationProperties
be on other @Configuration
class?Hullaballoonatic
11/05/2019, 8:45 PMlateinit var
syntaxHullaballoonatic
11/05/2019, 8:46 PMDariusz Kuc
11/05/2019, 8:48 PM@ConstructorBinding
is new thing so maybe it is pretty finicky 🤷Hullaballoonatic
11/05/2019, 8:49 PMjtravis
11/05/2019, 11:14 PMHullaballoonatic
11/06/2019, 12:23 AM@ConstructorBinding
@ConfigurationProperties("foo")
class FooConfiguration(val bar: String)
Hullaballoonatic
11/06/2019, 12:24 AMDariusz Kuc
11/06/2019, 12:51 AMHullaballoonatic
11/06/2019, 8:35 PM@ConfigurationProperties
annotation would be superfluous and it could simply read:
@ConstructorBinding data class Foo(val bar: String, val baz: String)
Dariusz Kuc
11/06/2019, 8:37 PM@ConstructorBinding
annotation 🙂 unsure why pivotal decided to add that requirement inHullaballoonatic
11/06/2019, 10:54 PM@configuration
annotation should be able to realize which constructor arguments are autowired, and which are properties by checking the former then the latterHullaballoonatic
11/06/2019, 10:56 PMHullaballoonatic
11/08/2019, 12:13 AM@ConfigurationProperties
is highlighted as an error saying that this class is not designated as a component. if I add that annotation, everything still works fine, but then id
is highlighted as an error saying there are no String
beans. Calling wolf here is part of the reason I had such a hard time with it.Hullaballoonatic
11/08/2019, 12:13 AM@EnableResourceServer
@ConstructorBinding
@ConfigurationProperties("resource-server")
class ResourceServerConfiguration(private val id: String) : ResourceServerConfigurerAdapter()
Hullaballoonatic
11/08/2019, 12:16 AM