我使用Seam 2.2。我想使用反射从 Seam 组件中获取私有字段。所以我有:
LocalizationEditActionRoot localizationEditActionRoot = (LocalizationEditActionRoot) Component
.getInstance(LocalizationEditActionRoot.class, true);
Class currentClass = localizationEditActionRoot.getClass();
WebDavMockClient mockClient = new WebDavMockClient();
Field f = currentClass.getDeclaredField("davClient");
f.setAccessible(true);
f.set(localizationEditActionRoot, mockClient);
如果我想获得一个名为的字段,davClient(WebDavClient)
我会得到一个 NoSuchFieldException。该领域当然是注入。如果我尝试这样的事情:
Class currentClass = Class.forName("fr.isiom.bpms.admin.session.ext.action.root.LocalizationEditActionRoot");
WebDavMockClient mockClient = new WebDavMockClient();
Field f = currentClass.getDeclaredField("davClient");
f.setAccessible(true);
f.set(localizationEditActionRoot, mockClient);
我得到了这个字段davClient
,但值没有改变。他仍然是 WebDavClient 的实例,而不是 WebDavMockClient。如何更改该字段值?