我有一个结构如下的 EJB 应用程序。所有依赖项都保存在/lib
目录中并在所有 Web 模块之间共享。
├── app1_war
│ ├── index.jsp
│ ├── META-INF
│ └── WEB-INF
|
├── core.jar
├── app2_war
│ ├── META-INF
│ └── WEB-INF
|
├── app3_war
│ ├── META-INF
│ └── WEB-INF
|
├── lib
│ ├── struts2-core-2.3.8.jar
│ ├── webwork-2.2.7.jar
│ ├── xwork-1.2.3.jar
│ └── xwork-core-2.3.8.jar
|
├── META-INF
│ ├── application.xml
│ ├── MANIFEST.MF
|
├── app4_war
├── index.jsp
├── META-INF
└── WEB-INF
所有模块都使用struts2-core-2.3.8.jar
依赖项。当我在 Glassfish 上部署它时,我最终会遇到以下异常:
Exception starting filter struts2
java.lang.InstantiationException
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:124)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4685)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:5377)
at com.sun.enterprise.web.WebModule.start(WebModule.java:498)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:917)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:901)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:733)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2019)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1669)
[...]
Caused by: Unable to load configuration. - bean - jar:file:/opt/glassfish3/nodes/apps/fish1/applications/legacy/lib/struts2-core-2.3.8.jar!/struts-default.xml:29:72
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:483)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:264)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:120)
... 41 more
Caused by: Unable to load configuration. - bean - jar:file:/opt/glassfish3/nodes/apps/fish1/applications/legacy/lib/struts2-core-2.3.8.jar!/struts-default.xml:29:72
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:429)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:471)
... 45 more
Caused by: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - jar:file:/opt/glassfish3/nodes/apps/fish1/applications/legacy/lib/struts2-core-2.3.8.jar!/struts-default.xml:29:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:245)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:102)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:215)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
... 47 more
Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean - jar:file:/opt/glassfish3/nodes/apps/fish1/applications/legacy/lib/struts2-core-2.3.8.jar!/struts-default.xml:29:72 - bean - jar:file:/opt/glassfish3/nodes/apps/fish1/applications/legacy/lib/struts2-core-2.3.8.jar!/struts-default.xml:29:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:229)
我的猜测是,这是因为所有模块都共享相同的依赖项,因此每个模块都struts-default.xml
在其上下文中加载相同的文件。有谁知道如何解决这个问题?