请问如何实现“自动的”“dependency injection”?

我使用setter injection 实现dependency injection, 我现在的问题是,如何在不知道TagBeanImpl内部,有什么样静态引用的前提下, "自动地” 将这些静态引用赋值(注射进去)? 谢谢!!!

就好像用java的反射机制对某个类实例,变量赋值,方法调用一样。 我也可以在TagBeanImpl内部用个静态代码块来赋值,但加入第一次没成功咋办,所以总觉得不如在“外部”实现的好,没注入成功可以在来一次。

还有,TagBeanImpl声明的static reference全部是DAO接口,没有其它的。

public class TagBeanImpl implements TagBean {

//
private static TagCoreDao tagCoreDao;
private static TagTreeDao tagTreeDao;

public static TagCoreDao getTagCoreDao() {
return tagCoreDao;
}

public static void setTagCoreDao(TagCoreDao tagCoreDao) {
TagBeanImpl.tagCoreDao = tagCoreDao;
}

public static TagTreeDao getTagTreeDao() {
return tagTreeDao;
}

public static void setTagTreeDao(TagTreeDao tagTreeDao) {
TagBeanImpl.tagTreeDao = tagTreeDao;
}
}

首先去除静态概念,静态的对象实际就是永垂不朽的东西,世界上有永远不死的东西吗?没有,对象是有生命的,所以,去除使用静态的习惯,静态使用只是在很小很小范围中使用,所以,在这个小应用范围谈不上注射依赖这些正常对象的设计课题。

自动注射可以看看Picocontainer或Jdon框架。

谢谢!banq!