com.opensymphony.xwork2.inject.DependencyException:com.opensymphony.xwork2.inject.ContainerImpl $ MissingDependencyException

时间:2014-09-12 10:30:10

标签: xml struts2 web.xml servlet-filters

在部署我的war文件时,我得到以下异常:

SEVERE: Exception starting filter struts2
com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=com.opensymphony.xwork2.ObjectFactory, name='default'] in public void com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.setObjectFactory(com.opensymphony.xwork2.ObjectFactory). - Class: com.opensymphony.xwork2.inject.ContainerImpl
File: ContainerImpl.java
Method: addInjectorsForMembers
Line: 144 - com/opensymphony/xwork2/inject/ContainerImpl.java:144:-1
        at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:501)
        at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
        at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)
        at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
        at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4809)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5485)
        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:632)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1073)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        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:745)
Caused by: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=com.opensymphony.xwork2.ObjectFactory, name='default'] in public void com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.setObjectFactory(com.opensymphony.xwork2.ObjectFactory).
        at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:144)
        at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMethods(ContainerImpl.java:113)
        at com.opensymphony.xwork2.inject.ContainerImpl.addInjectors(ContainerImpl.java:90)
        at com.opensymphony.xwork2.inject.ContainerImpl.addInjectors(ContainerImpl.java:86)
        at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:71)
        at com.opensymphony.xwork2.inject.ContainerImpl$1.create(ContainerImpl.java:67)
        at com.opensymphony.xwork2.inject.util.ReferenceCache$CallableCreate.call(ReferenceCache.java:150)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at com.opensymphony.xwork2.inject.util.ReferenceCache.internalCreate(ReferenceCache.java:76)
        at com.opensymphony.xwork2.inject.util.ReferenceCache.get(ReferenceCache.java:116)
        at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:490)
        at com.opensymphony.xwork2.inject.ContainerImpl$6.call(ContainerImpl.java:530)
        at com.opensymphony.xwork2.inject.ContainerImpl$6.call(ContainerImpl.java:528)
        at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:584)
        at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:528)
        at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:257)
        at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
        at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:445)
        at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:489)

我已根据某些帖子的建议在struts-default.xml init-param中添加了web.xml

仍然没有用!!

我错过了什么吗?

web.xml与下面类似

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="http://java.sun.com/xml/ns/javaee" 
   xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
   http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
   id="WebApp_ID" version="3.0">

   <display-name>Struts 2</display-name>
   <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
   <filter>
      <filter-name>struts2</filter-name>
      <filter-class>
         org.apache.struts2.dispatcher.FilterDispatcher
      </filter-class>
   </filter>

   <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
   </filter-mapping>
</web-app>

struts.xml与下面类似

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
   "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
   "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
   <package name="helloworld" extends="struts-default">

      <action name="hello" 
            class="com.tutorialspoint.struts2.HelloWorldAction" 
            method="execute">
            <result name="success">/HelloWorld.jsp</result>
      </action>
   </package>
</struts>

2 个答案:

答案 0 :(得分:1)

  1. 删除已弃用的 FilterDispatcher and set the new filter
  2. 更正您的DTD:在 web.xml 中,您将2.53.0混合在一起。根据您的应用服务器规范,所有2.5或全部3.0(或所有2.4。在 struts.xml 中,它应该是2.3,除非您使用的是旧版本(并且)。
  3. 确保您已包含all the required dependencies,每个仅包含一次,并且所有正确版本。

答案 1 :(得分:0)

我遇到了同样的问题。我在资源文件夹下移动了struts.xml文件,以便它出现在类路径中。我删除了指向struts位置的过滤器StrutsPrepareAndExecuteFilter的init参数。我正在使用以下版本的库以及maven。

<struts.version>2.3.16.3</struts.version>
<spring.version>4.1.2.RELEASE</spring.version>
<struts.spring.plugin>2.3.16.3</struts.spring.plugin>