通用配置 Web 层只是不少层中的一层...它是服务器端应用的一个入口. 全部 Web 框架都适用的 Spring 配置 在咱们的web应用里面找到你的web.xml 在里面加入以下配置就能够启动spring容器了 加载 Spring 配置文件 <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext*.xml</param-value> </context-param> 初始化spring容器 <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> Listener 是在 Servlet API 2.3 版本中才加入的 因此你的版本必须在2.3(或)之上 若是你用的版本在这个之下 那么你就得这么配置了 加载 Spring 配置文件 <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext*.xml</param-value> </context-param> 初始化spring容器 <servlet> <servlet-name>context</servlet-name> <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> 经过struts1.x来启动spring容器 初始化spring容器 <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="/WEB-INF/action-servlet.xml.xml,/WEB-INF/applicationContext.xml"/> </plug-in> Action 依赖关系 把action 交给spring管理 <controller> <set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/> </controller> <action path="/users" .../> 你必须在 action-servlet.xml 中将 Action bean 的名字定义为 “/users”: <bean name="/users" .../> 这样所有的action就能够由spring来管理了 若果你要对指定的某一个action交给spring来管理的话那么你能够这样配置 <action path="/user" type="org.springframework.web.struts.DelegatingActionProxy"> </action> 可是不推荐这么搞,若是这么作的话 你要是有多个action的话 你就得每一个的type指定为 org.springframework.web.struts.DelegatingActionProxy 我的以为有些麻烦 呵呵