Skip to content
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

Allow to inject enum with package visibility [SPR-16284] #20831

spring-projects-issues opened this issue Dec 11, 2017 · 0 comments
in: core status: backported type: enhancement


Copy link

spring-projects-issues commented Dec 11, 2017

Hans Desmet opened SPR-16284 and commented

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 {

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'/>

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.

Affects: 5.0.2

Reference URL:

Issue Links:

Referenced from: commits 4bb8375, 9beb978

Backported to: 4.3.14

@spring-projects-issues spring-projects-issues added status: backported type: enhancement in: core labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.0.3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: core status: backported type: enhancement
None yet

No branches or pull requests

2 participants