我正在尝试使用 Picocontainer Web (picocontainer-web-core-2.5.1.jar)。
我已经配置了所有内容,并且检查了一切正常,直到尝试从容器中检索任何内容...:p
我虽然应该使用 PicoServletContainerFilter 类中的静态方法 getRequestComponentForThread(Class type),它看起来像这样:
public static Object getRequestComponentForThread(Class type) {
MutablePicoContainer requestContainer = ServletFilter.currentRequestContainer.get();
MutablePicoContainer container = new DefaultPicoContainer(requestContainer);
container.addComponent(type);
return container.getComponent(type);
}
但正如您所看到的,在该方法中,创建了 DefaultPicoContainer 的新实例,并且正在注册我试图检索的类型。
- 如果 type 是 Class - 创建并返回新实例,而不是从父容器缓存一个...
- 如果类型是接口 - 在第 3 行 (addComponent) 抛出运行时异常(“'ExampleInterface' 不可实例化”)。
我的问题是:如何使用这个库?我很确定我理解它,但是这种方法的实现让我大吃一惊......