我有一个带有多个模块的Maven项目。在四个模块中,其中两个是Web模块。
这是结构。
MyProject | |__ api | |__ commons | |__ web_child | |__ web_main
web_main模块是主要web_child模块,也可以包含模块。
web_main
web_child
web_child 模块结构是
web_child | |__ src/main/java //java action classes and all |__ src/main/resources | |__ struts-config.xml | |__ WEB-INF |__ JSP Pages
web_main 模块结构是
web_main | |__ src/main/java //java action classes and all |__ src/main/resources | |__ struts.xml | |__ WEB-INF |__ JSP Pages
这两个模块都是war。
war
web-main取决于所有模块,并web-child取决于前两个(API和公用)模块。
web-main
web-child
在web-main的pom.xml,我加入了依赖性web-child,它会自动添加另外两个jar。
pom.xml
主模块web-main在服务器上运行良好。
但是当我尝试web-child单独运行该模块时,它显示出如下错误
There is no Action mapped for namespace [/] and action name [childMenu] associated with context path ...
因为它不占用 struts-config.xml
struts-config.xml
当我将文件重命名为时struts.xml,web-child工作正常。但是那个时候主模块没有运行。
struts.xml
因此,我想将struts.xmlin子模块重命名为,struts-config.xml并需要明确指定它。
我正在使用Struts2。但是我已经尝试了以下内容,但web.xml显然没有用
web.xml
<servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>../resources/struts-config.xml</param-value> </init-param> </servlet>
如何解决这个问题呢?
更新1
嗨,我在我的web-child web.xml文件中添加了以下内容
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> <init-param> <param-name>config</param-name> <param-value>struts-config.xml</param-value> </init-param> </filter>
我正在追随异常。我需要添加任何依赖项吗?
SEVERE: Exception starting filter struts2 Unable to load configuration. - [unknown location] 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.initFilter(ApplicationFilterConfig.java:281) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262) at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:107) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4775) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5452) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:976) at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1653) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:724) Caused by: Unable to load configuration. - [unknown location] at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:71) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:429) at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:471) ... 19 more Caused by: Cannot locate the chosen ObjectFactory implementation: spring - [unknown location] at org.apache.struts2.config.BeanSelectionProvider.alias(BeanSelectionProvider.java:391) at org.apache.struts2.config.BeanSelectionProvider.alias(BeanSelectionProvider.java:362) at org.apache.struts2.config.BeanSelectionProvider.register(BeanSelectionProvider.java:288) at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:215) at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:68) ... 21 more
在struts过滤器初始化参数中明确指定配置文件。
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> <init-param> <param-name>config</param-name> <param-value>struts.xml,struts-config.xml,struts-default.xml,struts-plugin.xml</param-value> </init-param> </filter>