我一直在尝试向合同注入服务:
@org.jvnet.hk2.annotations.Contract
public interface CategoryDAO{
}
@org.jvnet.hk2.annotations.Service
public class HibernateCategoryDAO implements CategoryDAO
}
@org.jvnet.hk2.annotations.Service
public class MyCategoryManager implements CategoryManager {
@javax.inject.Inject
CategoryDAO categoryDAO;
}
但是 categoryDAO 为空。
我什至尝试绑定它:
public class ServiceBinder implements Binder {
@Override
public void bind(DynamicConfiguration config) {
config.bind(BuilderHelper.link(HibernateCategoryDAO.class).to(CategoryDAO.class).build());
}
}
但它仍然为空。
我像这样初始化MyCategoryManager
with Reflections 框架:
Set<?> managers = Reflections.getSubTypesOf(CategoryManager.class);