Я пытаюсь внедрить java enum через контекст Spring, используя <util:constant
.
Вот что я сделал.В моей весенней конфигурации у меня есть следующая запись
<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>
Здесь я пытаюсь использовать Enum ADSKContentGroup для внедрения в свойство ame моего бина (ADSKContentGroup).
Вотenum:
public enum MetadataTypeEnum {
CONTENT_GROUP ("ADSKContentGroup"),
private String metadataType;
private MetadataTypeEnum(String metadataType) {
this.metadataType = metadataType;
}
public String getMetadataType() {
return this.metadataType;
}
}
Вот этот bean-компонент:
public class ADSKContentGroup extends Metadata {
public ADSKContentGroup(){
}
}
Боб происходит из базового класса, который имеет установщик атрибута name
Вот определение класса:
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
Не уверен, что не так с моим подходом.
Любой указатель высоко ценится.