---
title: "Struts2 Dispatcher initialization failed No mapping found for dependency default"
author: "chainhou"
date: "2013-04-10T16:41:10Z"
tags: []
categories: ["开源软件"]
slug: "struts2-dispatcher-initialization-failed-no-mapping-found-for-dependency-default"
draft: false
lastmod: "2013-04-10T16:41:10Z"
id: 1845210
url: "https://chainhou.iteye.com/blog/1845210"
---

在struts2的使用时如果发现以下异常信息，

```java

严重: Dispatcher initialization failed
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).

```


可能原因是：你在web.xml中重新指定了struts.xml的位置，导致struts.xml需要使用的struts-default.xml无法找到。
解决方式是在web.xml中也添加struts-default.xml，如下：

```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-default.xml,struts-plugin.xml,struts.xml</param-value>
		</init-param>
	</filter>


```

param-value项指定了需要的文件。