0, Spring本身的一些工作(比如,根上下文的建立)可以在ContextLoaderServlet或ContextLoaderListener中完成;
1, 如果需要使用Spring MVC就需要引入DispatcherServlet,否則可以不用引入這個servlet,
而引入其他的servlet(比如,如果webApplication需要使用struts MVC,就需要引入struts的servlet,如ActionServlet).
2, Spring與Struts的結合:
??方法一:
????a. 利用Spring的ContextLoaderServlet或ContextLoaderListener加載Spring所需要的Bean定義及ApplicationContext的建立等;
????b. 定義Struts所需要的Dispatcher類ActionServlet,其中a,b兩步是獨立的;
????c. 在Struts的action中引用Spring中的bean定義時,可以直接使用WebApplicationContextUtil
????
????如: a. web.xml的配置:
??????<context-param>
???????<param-name>contextConfigLocation</param-name>
???????<param-value>/WEB-INF/beanDefineA.xml</param-value>
??????</context-param>
??????
??????<servlet>
???????<servlet-name>ContextLoader</servlet-name>
???????<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
???????<load-on-startup>1</load-on-startup>
??????</servlet>
??????<servlet>
????????? <servlet-name>action</servlet-name>
????????? <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
????????? <init-param>
??????????? <param-name>config</param-name>
??????????? <param-value>/WEB-INF/struts-config.xml</param-value>
????????? </init-param>
????????? <load-on-startup>2</load-on-startup>
??????? </servlet>
??????
??????<servlet-mapping>
???????<servlet-name>ContextLoader</servlet-name>
???????<url-pattern>/</url-pattern>
??????</servlet-mapping>
??????<servlet-mapping>
???????<servlet-name>action</servlet-name>
???????<url-pattern>*.do</url-pattern>
??????</servlet-mapping>
??????
??????b. bean定義文件內容如下:
???????<bean id="test" class="com.info.test">
?????? ??<property name="id">
?????? ???<value>1</value>
?????? ??</property>
?????? ??<property name="name">
?????????<value>zqbchina</value>
????????</property>
?????? ??<property name="age">
?????????<value>12</value>
????????</property>
?????? ?</bean>
?????? ?
?????? c. action中的引用:
?????? ...
?????? ServletContext sc = request.getSession().getServletContext();
??????WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(sc);
??????test t = (test)wac.getBean("test");
??????...