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