---
title: "在WEB工程下搭建spring2.5"
author: "myeclipse600"
date: "2013-05-10T16:29:11Z"
tags: []
categories: ["Web前端"]
slug: "web-spring2-5"
draft: false
lastmod: "2013-05-10T16:29:11Z"
id: 1866856
url: "https://myeclipse600.iteye.com/blog/1866856"
---

1.创建WEB工程

 

2.添加spring2.5.6必须得jar包，spring.jar和common-logging.jar,

 

3.新建spring的配置文件，可以是一或多个配置文件，开发中大部分都会是多个配置文件

4.在web.xml来加载spring

Xml代码

1. **&lt;context-param&gt;**
2. **&lt;param-name&gt;**contextConfigLocation**&lt;/param-name&gt;**
3. **&lt;param-value&gt;**/WEB-INF/applicationContext-common.xml,/WEB-INF/applicationContext-dao.xml,/WEB-INF/applicationContext-service.xml**&lt;/param-value&gt;**
4. **&lt;/context-param&gt;**

上面的指定spring配置文件的位置可以写成下面形式

Xml代码

1. **&lt;context-param&gt;**
2. **&lt;param-name&gt;**contextConfigLocation**&lt;/param-name&gt;**
3. **&lt;param-value&gt;**/WEB-INF/applicationContext-\*.xml**&lt;/param-value&gt;**
4. **&lt;/context-param&gt;**
5. **&lt;listener&gt;**
6. **&lt;listener-class&gt;**
7. org.springframework.web.context.ContextLoaderListener
8. **&lt;/listener-class&gt;**
9. **&lt;/listener&gt;**

  

多个xml文件的组装方式有二种，一：采用加载多个xml的方式，制定多个位置二：采用import标签倒入多个文件的方式

Xml代码

1. **&lt;beans&gt;**
2. **&lt;import** resource="service.xml"**/&gt;**
3. **&lt;import** resource="dao.xml"**/&gt;**
4. **&lt;/beans&gt;**