java - Injecting an enum with Spring -
i'm trying inject java enum through spring context using <util:constant.
here's i've done. in spring config, i've following entry
<util:constant id="content" static-field="com.test.taxonomy.model.metadatatypeenum.content_group" /> <util:constant id="category" static-field="com.test.taxonomy.model.metadatatypeenum.category" />     <bean id="adskcontentgroup" class="com.test.taxonomy.model.adskcontentgroup" scope="prototype">   <property name="name" ref="content" />  </bean>   here, i'm trying leverage enum adskcontentgroup injected in bean's (adskcontentgroup) ame property.
here's enum :
public enum metadatatypeenum {   content_group ("adskcontentgroup"),    private string metadatatype;    private metadatatypeenum(string metadatatype) {     this.metadatatype = metadatatype;   }   public string getmetadatatype() {     return this.metadatatype;   } }   here's bean :
public class adskcontentgroup extends metadata {   public adskcontentgroup(){   } }   the bean extends base class has setter name attribute
here's class definition:
public class metadata {   private metadatatypeenum name;   private string value;    public string getname() {     return name.getmetadatatype();   }    public void setname(metadatatypeenum name) {     this.name = name;   } }   in runtime, i'm getting following exception
error com.test.taxonomy.plugin.taxonomypluginimpl  - error in creating metadata mapping :error creating bean name 'adskcontentgroup' defined in servletcontext resource [/web-inf/beans.xml]: initialization of bean failed; nested exception org.springframework.beans.typemismatchexception: failed convert property value of type [com.test.taxonomy.model.metadatatypeenum] required type [java.lang.string] property 'name'; nested exception java.lang.illegalargumentexception: original must not null   org.springframework.beans.factory.beancreationexception: error creating bean name 'adskcontentgroup' defined in servletcontext resource [/web-inf/beans.xml]: initialization of bean failed; nested exception org.springframework.beans.typemismatchexception: failed convert property value of type [com.test.taxonomy.model.metadatatypeenum] required type [java.lang.string] property 'name'; nested exception java.lang.illegalargumentexception: original must not null   not sure what's going wrong approach.
any pointer highly appreciated.
- thanks
 
your metadata class ill-designed javabean, not conform spec: setter uses parameter of type metadatatypeenum, return type of getter string.
Comments
Post a Comment