Skip to content

Provider<...> declaration for @Value method argument fails with TypeMismatchException [SPR-12297] #16903

Closed
@spring-projects-issues

Description

@spring-projects-issues

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.

public class Foo {
  private final Provider<Integer> changeableIntegerProperty;
 
  public Foo(Provider<Integer> changeableIntegerProperty) {
    this.changeableIntegerProperty = changeableIntegerProperty;
 }

 public void someOperation() {
     changeableIntegerProperty.get(); // Gets current value of the property
 }
}

@Configuration
public class FooConfig {
  @Bean
   public Foo foo(@Value("${fooProp}") Provider<Integer> fooProp) {
        return new Foo(fooProp);
   }
}

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:

Backported to: 4.0.8, 3.2.12

1 votes, 3 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions