码迷,mamicode.com
首页 > 编程语言 > 详细

综合-----Web工程中启动Spring的三种方法

时间:2014-12-05 17:23:57      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:web   spring   

一、利用Spring 自带的Listener(推荐)

web.xml中配置如下

<context-param>
     <!-- 名字固定 -->
     <param-name>contextConfigLocation</param-name>
     <!-- 值为Spring配置文件的路径 -->
     <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
     <!-- <param-value>classpath:spring/applicationContext.xml</param-value> -->
</context-param>
<listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


 二、利用Spring自带的 servlet

web.xml中配置如下

<context-param>
     <!-- 名字固定 -->
     <param-name>contextConfigLocation</param-name>
     <!-- 值为Spring配置文件的路径 -->
     <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
     <!-- <param-value>classpath:spring/applicationContext.xml</param-value> -->
</context-param>
<servlet>
     <!-- 名字固定 -->
     <servlet-name>context</servlet-name>
     <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
     <load-on-startup>1</load-on-startup>
</servlet>


 三、利用第三方WEB框架定义的<plug-in > :struts框架

Struts的配置文件中配置如下

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
     <set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" />
</plug-in>







综合-----Web工程中启动Spring的三种方法

标签:web   spring   

原文地址:http://blog.csdn.net/hekewangzi/article/details/41750001

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!