Comments (3)
@MADEINCHINA @ConstructorBinding
is designed to be used only on a constructor, if there's a single constructor it shouldn't be necessary. Can you provide more details about what you're trying to do and why you want to add the annotation to the type?
from spring-boot.
@MADEINCHINA
@ConstructorBinding
is designed to be used only on a constructor, if there's a single constructor it shouldn't be necessary. Can you provide more details about what you're trying to do and why you want to add the annotation to the type?
It's will raise a problem if upgrade from 2.x version. for 2.x version ConstructorBinding support ElementType.TYPE.
which means that we can add @ConstructorBinding to a data class and the recommended way to manage application properties with Kotlin can be found here spring-boot-kotlin
@ConstructorBinding in order to be able to use read-only properties.
@ConstructorBinding
@ConfigurationProperties("blog")
data class BlogProperties(var title: String, val banner: Banner) {
data class Banner(val title: String? = null, val content: String)
}
kotlinlang - getters-and-setters
The full syntax of a read-only property declaration differs from a mutable one in two ways: it starts with val instead of var and does not allow a setter
from spring-boot.
I can't see a need for @ConstructorBinding
in your example. Both BlogProperties
and Banner
have only a single constructor so we can automatically identify the constructor to use. If you declare your data class with a secondary constructor, you can use @ConstructorBinding
to identify the constructor that should be used with the help of the constructor
keyword:
@ConfigurationProperties("blog")
data class BlogProperties @ConstructorBinding constructor(val title: String, val banner: Banner) {
constructor(banner: Banner) : this("Default title", banner)
data class Banner(val title: String? = null, val content: String)
}
Here, the constructor that takes a String
and a Banner
will be used for configuration property binding.
Given the above, I'm going to close this issue. If there's a situation where binding to a data class still does not work, please provide a complete yet minimal sample that reproduces the problem. We can then re-open this issue and take another look.
from spring-boot.
Related Issues (20)
- Upgrade to Spring AMQP 3.1.3
- Upgrade to Spring Data Bom 2023.1.4
- Upgrade to Spring Framework 6.1.5
- Upgrade to Spring Integration 6.2.3
- Upgrade to Spring Kafka 3.1.3
- Upgrade to Spring Pulsar 1.0.4
- Upgrade to Spring Security 6.2.3
- Upgrade to Spring Session 3.2.2
- Upgrade to Micrometer 1.13.0-M2
- Upgrade to Micrometer Tracing 1.3.0-M2
- Upgrade to Spring AMQP 3.1.3
- Upgrade to Spring Authorization Server 1.3.0-M3
- Upgrade to Spring Data Bom 2024.0.0-M2 HOT 1
- Upgrade to Spring Framework 6.1.5
- Upgrade to Spring GraphQL 1.3.0-RC1
- Upgrade to Spring Integration 6.3.0-M2
- Upgrade to Spring Kafka 3.2.0-M2
- Upgrade to Spring Pulsar 1.1.0-M2
- Upgrade to Spring Security 6.3.0-M3
- Upgrade to Spring Session 3.3.0-M3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-boot.