How to assign bean's property an Enum value in Spring config file?

前端 未结 9 935
遥遥无期
遥遥无期 2020-11-28 06:16

I have a standalone enum type defined, something like this:

package my.pkg.types;

public enum MyEnumType {
    TYPE1,
    TYPE2
}

Now, I w

9条回答
  •  一整个雨季
    2020-11-28 06:29

    Use the value child element instead of the value attribute and specify the Enum class name:

    
        ALIEN
    
    

    The advantage of this approach over just writing value="ALIEN" is that it also works if Spring can't infer the actual type of the enum from the property (e.g. the property's declared type is an interface).Adapted from araqnid's comment.

提交回复
热议问题