-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@Autowired is sometimes required on the constructor of a ConfigurationProperties class just to ensure that the correct metadata is generated #34031
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
@sobychacko is your expectation that both |
@wilkinsona Thank you for the reply. When I spoke to @philwebb about this issue, I thought there might be a way to get around that limitation. My expectation was that both constructor-binding and JavaBean styles could co-exist. In the Kafka binder for Spring Cloud Stream, we have a |
It looks like the constructor that consumes
As far as I can tell, the problem here is that the annotation processor that generates the metadata may incorrectly determine that constructor binding is going to be used when it's actually JavaBean binding that will be performed. |
I tried the |
With the above {
"groups": [
{
"name": "test.properties",
"type": "com.example.demo.TestProperties",
"sourceType": "com.example.demo.TestProperties"
}
],
"properties": [
{
"name": "test.properties.custom",
"type": "java.lang.String",
"sourceType": "com.example.demo.TestProperties"
}
],
"hints": []
} (The app also won't start as there are no Boot 3.0 produces the following metadata: {
"groups": [
{
"name": "test.properties",
"type": "com.example.demo.TestProperties",
"sourceType": "com.example.demo.TestProperties"
}
],
"properties": [
{
"name": "test.properties.my-data",
"type": "com.example.demo.MyData",
"sourceType": "com.example.demo.TestProperties"
}
],
"hints": []
} This is due to the improved
While the constructor injection is manual in the {
"groups": [
{
"name": "test.properties",
"type": "com.example.demo.TestProperties",
"sourceType": "com.example.demo.TestProperties"
}
],
"properties": [
{
"name": "test.properties.custom",
"type": "java.lang.String",
"sourceType": "com.example.demo.TestProperties"
}
],
"hints": []
} Things seem to be working as they should and @sobychacko Can you please double-check that |
Ah ok. I did see the same output that you got above for Boot 3.0. I will try the |
Adding |
When generating configuration metadata (spring-configuration-metadata.json), KafkaBinderConfigurationProperties class is missing all the information except for the constructor bound KafkaProperties. We need to add the @Autowired on the constructor so that Boot will not do a constructor binding and thus include all the JavaBeans style properties in the metadata. See this Boot issue for more details. spring-projects/spring-boot#34031 In addition, this @Autowired is necessary for the properties to be correctly bound when running in native mode. Resolves spring-cloud#2640 Resolves spring-cloud#2644
Thanks, @sobychacko. I'm going to leave this open for a bit as I'd like to discuss things with the team to see if we can figure out a way to make |
We're going to look at a way to signal that bean binding should be used that isn't |
I started looking at adding an enum to |
With thanks to @sobychacko for verifying, this has been fixed by #35564. |
Using Boot
3.0.2
, we see a behavior in which only properties injected through a constructor binding is generated as part ofspring-configuration-metadata.json.
Any other properties in theConfigurationProperties
class are omitted from it.Let's say we have the following
ConfigurationProperties
class.and
We see the following in the generated
spring-configuration-metadata.json.
Thecustom
property in the aboveConfigurationProperty
class is not present.This issue is related to spring-cloud/spring-cloud-stream#2640
The text was updated successfully, but these errors were encountered: