I have below POJO in java which is used in Spring boot app to inject properties from YML during the app startup. Trying to convert the app into Kotlin but I have struggle implementing the values injected when I converted the POJO to data class.
@Component
@ConfigurationProperties("rest")
@Data
public class RestProperties {
private final Client client = new Client();
@Data
public static class Client {
private int defaultMaxTotalConnections;
private int defaultMaxConnectionsPerRoute;
private int defaultReadTimeout;
}
}
I have tried below solution but didn't work.
@Component
@ConfigurationProperties("rest")
class RestProperties {
val client = Client()
class Client() {
constructor(
defaultMaxTotalConnections: Int,
defaultMaxConnectionsPerRoute: Int,
defaultReadTimeout: Int
) : this()
}
}
@Component
@ConfigurationProperties("rest")
class RestProperties {
val client = Client()
class Client {
var defaultMaxTotalConnections: Int = 50
set(defaultMaxTotalConnections) {
field = this.defaultMaxTotalConnections
}
var defaultMaxConnectionsPerRoute: Int = 10
set(defaultMaxConnectionsPerRoute) {
field = this.defaultMaxConnectionsPerRoute
}
var defaultReadTimeout: Int = 15000
set(defaultReadTimeout) {
field = this.defaultReadTimeout
}
}
}
second code works but the values are not injected from YML. Appreciate your help.