开发者

Spring annotation scan tag

开发者 https://www.devze.com 2023-02-14 02:17 出处:网络
I have classes, which have not public constructor (dicts, project started write in java 1.4, where there was no enum).

I have classes, which have not public constructor (dicts, project started write in java 1.4, where there was no enum).

@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;
    }
}

I want to initialize the beans like

<bean parent="dict-wrapper-value" p:value="a_FOO"/>

I was create the class

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()))
}
}

what convert string开发者_运维知识库 to dict, using dict's class, but I want get class description using spring xml config like <context:annotation-config/>, but <context:annotation-config/> trying to get instance of class and it has not public constructor.


You can not simply create an instance of this class. You need a (Spring) Factory to create the objects.

0

精彩评论

暂无评论...
验证码 换一张
取 消