Struts2-core common dependency between ejb modules

I have an EJB application with the structure below. All dependencies are stored in a directory /lib

and distributed to all web modules.

β”œβ”€β”€ 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

      

All modules use dependencies struts2-core-2.3.8.jar

. When I deploy this to Glassfish I get the below exception:

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)

      

My guess is that this is because all modules use the same dependencies, and hence, each one loads the same file struts-default.xml

into its own context. Does anyone know how to solve this?

+3


source to share


1 answer


This is a late answer, but anyway, here are my thoughts on this issue:

I am having similar problems with "sharing" some of the dependencies in an EAR file. What I can tell you is that when the context is loaded, Struts is initialized in the first path of the WAR path (using objectfactory, in turn, usually Spring). Then when the other wars are loaded, they have different contexts, but they are included in the same class hierarchy, Struts is initialized again, but finds that it has already been initialized.



Thus, you cannot share these types of dependencies because they must live in their Servlet context. Thus, you must include them in every WAR.

If you find a better solution please share it. But if not, I hope the above comment helps you.

0


source







All Articles