Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Spring注入枚举_Java_Spring_Enums - Fatal编程技术网

Java 使用Spring注入枚举

Java 使用Spring注入枚举,java,spring,enums,Java,Spring,Enums,我正试图使用通过spring上下文注入java enum,您的元数据类是设计不良的JavaBean,它不符合规范:setter使用类型为MetadataTypeEnum的参数,但getter的返回类型是字符串java的哪个版本和spring的哪个版本 <util:constant id="Content" static-field="com.test.taxonomy.model.MetadataTypeEnum.CONTENT_GROUP" /> <util:constant

我正试图使用
通过spring上下文注入java enum,您的
元数据
类是设计不良的JavaBean,它不符合规范:setter使用类型为
MetadataTypeEnum
的参数,但getter的返回类型是
字符串

java的哪个版本和spring的哪个版本
<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>
public enum MetadataTypeEnum {
  CONTENT_GROUP ("ADSKContentGroup"),

  private String metadataType;

  private MetadataTypeEnum(String metadataType) {
    this.metadataType = metadataType;
  }
  public String getMetadataType() {
    return this.metadataType;
  }
}
public class ADSKContentGroup extends Metadata {
  public ADSKContentGroup(){
  }
}
public class Metadata {
  private MetadataTypeEnum name;
  private String value;

  public String getName() {
    return name.getMetadataType();
  }

  public void setName(MetadataTypeEnum name) {
    this.name = name;
  }
}
ERROR com.test.taxonomy.plugin.TaxonomyPluginImpl  - Error in creating metadata mapping :Error creating bean with name 'ADSKContentGroup' defined in ServletContext resource [/WEB-INF/beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.test.taxonomy.model.MetadataTypeEnum] to required type [java.lang.String] for property 'name'; nested exception is java.lang.IllegalArgumentException: Original must not be null  
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ADSKContentGroup' defined in ServletContext resource [/WEB-INF/beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.test.taxonomy.model.MetadataTypeEnum] to required type [java.lang.String] for property 'name'; nested exception is java.lang.IllegalArgumentException: Original must not be null