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

Allow to inject enum with package visibility

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Complete
    • 5.0.2
    • 4.3.14, 5.0.3
    • Core:DI
    • None

    Description

      A class with package visibility can be injected in a bean.
      An enum can only be injected if it has public visibility.
      Given a class

      class MyClass {
        private final String value;
        public MyClass(String value) {
          this.value = value;
        }	
      }
      

      an enum

      enum MyEnum {
        VALUE
      }
      

      a bean class

      class MyBean {
        private final MyClass myClass;
        private final MyEnum myEnum;
        public MyBean(MyClass myClass, MyEnum myEnum) {
          this.myClass = myClass;
          this.myEnum = myEnum;
        }
      }
      

      and following bean definition:

      <bean class='enumproblem.MyBean'>
        <constructor-arg value='value'/>
        <constructor-arg value='VALUE'/>
      </bean>
      

      you get an exception:java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'enumproblem.MyEnum': no matching editors or conversion strategy found

      When you change the visibility of the enum to public, the exception dissapears.

      Attachments

        Issue Links

          Activity

            People

              juergen.hoeller Juergen Hoeller
              desmethans Hans Desmet
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                3 years, 38 weeks, 1 day ago