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
个人觉得有些麻烦 呵呵