我在 weblogic 10.3.5.0 上遇到了 Richfaces 4.3.1 的问题,在部署时会发生以下异常:
java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! duplicate key: class javax.faces.validator.LongRangeValidator
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:290)
at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:481)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:181)
Truncated. see log file for complete stacktrace
Caused By: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! duplicate key: class javax.faces.validator.LongRangeValidator
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:351)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:222)
at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:481)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
Truncated. see log file for complete stacktrace
Caused By: java.lang.IllegalArgumentException: duplicate key: class javax.faces.validator.LongRangeValidator
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:115)
at com.google.common.collect.RegularImmutableMap.<init>(RegularImmutableMap.java:72)
at com.google.common.collect.ImmutableMap$Builder.fromEntryList(ImmutableMap.java:245)
at com.google.common.collect.ImmutableMap$Builder.build(ImmutableMap.java:231)
at org.richfaces.javascript.ClientServiceConfigParser.parseConfig(ClientServiceConfigParser.java:53)
我查看了 ClientServiceConfigParser 并对其进行了调试,发现它最终从 richfaces-components-ui-4.3.1.Final.jar 加载 /META-INF/csv.xml 两次
有问题的方法是:
public static Map<Class<?>, LibraryFunction> parseConfig(String name) {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (null == loader) {
loader = ClientServiceConfigParser.class.getClassLoader();
}
Builder<Class<?>, LibraryFunction> resultBuilder = ImmutableMap.builder();
try {
Enumeration<URL> resources = loader.getResources(name);
while (resources.hasMoreElements()) {
URL url = (URL) resources.nextElement();
resultBuilder.putAll(parse(loader, url));
}
} catch (IOException e) {
return Collections.emptyMap();
}
return resultBuilder.build();
}
这似乎与 Weblogic 的 ChangeAwareClassLoader ( weblogic.utils.classloaders.ChangeAwareClassLoader
) 有关。因为在内部org.richfaces.javascript.ClientServiceConfigParser.parseConfig(String)
运行时,ClassLoader loader = Thread.currentThread().getContextClassLoader();
它最终会返回ChangeAwareClassLoader
恰好获得相同资源的 2 个副本的结果。但是,如果我将加载器(使用调试器)清空以便它运行loader = ClientServiceConfigParser.class.getClassLoader();
,那么它最终会得到一个不同的类加载器:weblogic.utils.classloaders.GenericClassLoader
. 哪个不会获得相同资源的 2 个副本。
对于它的价值,我正在使用 maven 并以这种方式加载了richfaces:
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
</dependency>
在人们建议我加载了错误的 maven 依赖项之前,我可以告诉你它与以下内容无关:IllegalArgumentException: duplicate key (JSF)
因为使用调试器我确认loader.getResources(name);
返回完全相同的资源。
zip:C:/bea/user_projects/domains/test/servers/AdminServer/tmp/_WL_user/_appsdir_umsWebUI-jee-ear-1.0-SNAPSHOT_ear/6m7brt/lib/richfaces-components-ui-4.3.1.Final.jar!/META-INF/csv.xml
zip:C:/bea/user_projects/domains/test/servers/AdminServer/tmp/_WL_user/_appsdir_umsWebUI-jee-ear-1.0-SNAPSHOT_ear/6m7brt/lib/richfaces-components-ui-4.3.1.Final.jar!/META-INF/csv.xml
另外作为参考,我尝试了 JSF 论坛并在 weblogic 论坛上发了一个帖子,但我想我可能会在这里得到更好的回应。另外两个帖子在这里:
https://forums.oracle.com/forums/thread.jspa?threadID=2529414 https://community.jboss.org/thread/224100
所以除了编译我自己的富面孔版本之外,有没有人有任何解决方法的想法?如何禁用ChangeAwareClassLoader
可能?尝试禁用该类加载器时,我的 Google 搜索没有任何结果。