我有类,没有公共构造函数(dicts,项目在java 1.4中开始编写,没有枚举)。
@SpringContextAvailableDict(alias="a")
public class Class1 extends Dict<Object> {
protected String code;
protected String title;
public final static Class1 NULL = new Class1(null, null, Dict.NAME_NULL);
public final static Class1 FOO = new Class1("0", "e", "name1");
public final static Class1 BAR = new Class1("1", "j", "name2",);
private Class1(String code, String letterCode, String title) {
this.code = code;
this.title = title;
}
}
我想初始化像
这样的bean<bean parent="dict-wrapper-value" p:value="a_FOO"/>
我创建了这个类
public class StringToDictConverter extends PropertyEditorSupport {
protected Map<String, Class<?>> dicts = new HashMap<String, Class<?>>();
public StringToDictConverter() throws ClassNotFoundException{
ClassPathScanningCandidateComponentProvider scanner
= new ClassPathScanningCandidateComponentProvider(false);
scanner.addIncludeFilter(
new AnnotationTypeFilter(SpringContextAvailableDict.class));
for (BeanDefinition bd : scanner.findCandidateComponents("exmpl/*")){
// puting bd's class to dicts on key annotation parament 'alias';
}
}
@Override
public void setAsText(String text) throws IllegalArgumentException {
String[] name = text.split("_", 2);
setValue(dicts.get(name[0]).getField(name[1]).get(new Object()))
}
}
使用dict的类将字符串转换为dict,但我希望使用像<context:annotation-config/
&gt;这样的spring xml配置来获取类描述,但是<context:annotation-config/
&gt;试图获取类的实例,它没有公共构造函数。
答案 0 :(得分:0)
您不能简单地创建此类的实例。您需要一个(Spring)工厂来创建对象。