Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-12297

Provider<...> declaration for @Value method argument fails with TypeMismatchException

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 3.2.11, 4.0.7, 4.1.1
    • Fix Version/s: 3.2.12, 4.0.8, 4.1.2
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                juergen.hoeller Juergen Hoeller
                Reporter:
                saacharya Sanjay Acharya
                Last updater:
                St├ęphane Nicoll
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  3 years, 32 weeks, 6 days ago