天天看點

ssh項目中內建spring的三種方式

1.在web.xml中使用Listener,這也是我最常使用的。

  <context-param> 

    <param-name>contextConfigLocation</param-name> 

    <param-value>/WEB-INF/applicationContext.xml</param-value> 

  </context-param> 

  <listener> 

    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 

  </listener>

2.在web.xml中使用Servlet。

<web-app> 

     <context-param> 

            <param-name>contextConfigLocation</param-name> 

            <param-value>/WEB-INF/applicationContext-*.xml</param-value> 

     </context-param> 

     <servlet> 

            <servlet-name>SpringContextServlet</servlet-name> 

            <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class> 

            <load-on-startup>1</load-on-startup> 

     </servlet> 

</web-app>

3.在struts-config.xml中使用Plugin。

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> 

                <set-property property="contextConfigLocation"    

                        value="/WEB-INF/applicationContext.xml, 

                                     /WEB-INF/action-servlet.xml"/> 

</plug-in>

   這三種方式效果是一樣的。

     本文轉自NightWolves 51CTO部落格,原文連結:http://blog.51cto.com/yangfei520/309199,如需轉載請自行聯系原作者