-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Provider<...> declaration for @Value method argument fails with TypeMismatchException [SPR-12297] #16903
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
Comments
Juergen Hoeller commented As of #10747, this should work already, so I'll consider this as a bug. I suppose it just fails when type conversion is necessary... Anyway, if it's easy enough to fix, this is a candidate for a backport to 4.0.8 and 3.2.12 as well. Juergen |
Sanjay Acharya commented Thanks Juergen. This appears broken in 4.1.1 as well. My dirty workaround was to trick the TypeConverter with a custom one with the nesting level:
Setting the above as the TypeConverter default seems to get the code to work. I don't think this is the cleanest way to handle the same. |
Sanjay Acharya commented I am surprised if the String version even worked, my simple test using 4.1.1.RELEASE, seems to fail with String as the Provider type:
Where app.properties is simply:
If you set the TypeConverter to the one I mentioned via the below, the test passes:
|
Juergen Hoeller commented This seems to be a 4.x regression introduced through #14133, only failing for Juergen |
Juergen Hoeller commented Fixing that nestingLevel assertion makes it work, so it is indeed an accidental side effect from #14133. Fixed for 4.1.2; to be backported to 4.0.8. For the time being, it'll work fine for fields, just not for method arguments... Juergen |
Sanjay Acharya commented Great. Thanks much for the rapid turn around. We will look toward the new release. |
Juergen Hoeller commented Actually, this fails in 3.2.11 too, just with a fix necessary in a different place. Backported to 3.2.12 as well now. Juergen |
Sanjay Acharya opened SPR-12297 and commented
Would be very useful if Spring allowed for the injection of javax.inject.Provider along with
@Value
annotation for properties that could change at Runtime.If the same code shown above were attempted now, a TypeMismatchException gets thrown in TypeConverterSupport due to the nesting level of the parameter not set to 1.
My request for improvement is to allow the injection of java.inject.Provider along with
@Value
.Thanks.
Affects: 3.2.11, 4.0.7, 4.1.1
Issue Links:
@Value
and@Autowired
Backported to: 4.0.8, 3.2.12
1 votes, 3 watchers
The text was updated successfully, but these errors were encountered: