开发者

Lightweight class-loader for custom class initialization?

I want to inject some data to static class fields, which are generated from bulk of XML files.

class Foo {
    ...
    static MetaData xxx; 
    static MetaData yyy; 
}

The injection is very simple, it finds Foo.properties and parse xxx, yyy properties, then constructs the MetaData instances.

I'm not sure if IoC container may help this task, but it seems like not.

Because, the Foo maybe used by classes which are not loaded by IoC container.

My idea is开发者_Python百科, modify the context class loader to add some specific class initialization codes based on reflection.

Any idea?

EDIT There are a lot of IoC containers, I guess some of them may support initialization extensions maybe.


xxx, yyy initialized in lazy mode.

such as:

private static MetaData xxx=null;
public static MetaData getXXX(){
    if(xxx=null){
       xxx=parse("Foo.properties");
    }
    return xxx;
}

And if Ioc is a must to your program, BeanPostProcessors in Spring can be a choice. You could parse file and create MetaData object in BeanPostProcessor.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜