从2014年12月开始,一直在研究Spring的框架;并且在我们新的开发框架中得到应用;这篇文章记录了这段时间的成长记录,仅此先给共同成长的小白。
为了简单,我们选择使用maven来构建项目,通过maven可以控制引入jar的版本,大大简化了jar包的管理工作,废话不多说,创建一个项目
一、创建一个新项目
1、创建maven项目
2、选择 maven-archetype-webapp
3、填写groupId、artifactId、package
项目目录:

二、项目创建完成后修改默认的jdk、编译器等默认属性,我的项目选择的是jdk7
3、 引入Spring的jar
Xml代码
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
? ?
? ?
? ?
? ?
?
?
?
? ?
? ?
? ?
?
?
?
?
? ?
? ?
? ?
?
?
? ?
? ?
? ?
?
?
? ?
? ?
? ?
?
?
? ?
? ?
? ?
?
?
? ?
? ?
? ?
?
?
? ?
? ?
? ?
?
?
? ?
? ?
? ?
?
?
? ?
? ?
? ?
?
?
? ?
? ?
? ?
?
?
?
? ?
? ?
? ?
?
?
? ?
? ?
? ?
? ?
?
?
?
? ?
? ?
? ?
?
?
? ?
? ?
? ?
?
?
?
? ?
? ?
? ?
? ?
?
?
? ?
? ?
? ?
? ?
?
?
? ?
? ?
? ?
? ?
?
?
? ?
? ?
? ?
? ?
?
?
?
? ?
? ?
? ?
?
?
? ?
? ?
? ?
?
?
?
? ?
? ?
? ?
?
? ? ?
? ? ? ? ?
? ? ? ? ?
? ? ? ? ?
? ? ?
?
?
?
?
?
?
?
?
?
?
四、 创建Spring的配置文件
1、 启动Spring需要在web.xml中配置监听,使用SpringMVC需要配置Spring的servlet
Web.xml代码
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
? ? ? ?
? ?
?
?
?
?
?
? ?
? ?
? ?
? ? classpath:spring-*.xml
? ?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
2、Spring上下文配置文件ApplicationContext.xml用于配置Spring的通用配置
Applicationcontext.xml代码
?xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
?xmlns:context="http://www.springframework.org/schema/context"
?xsi:schemaLocation="http://www.springframework.org/schema/beans
? http://www.springframework.org/schema/beans/spring-beans.xsd
? http://www.springframework.org/schema/context
? http://www.springframework.org/schema/context/spring-context.xsd
? http://www.springframework.org/schema/aop
? http://www.springframework.org/schema/aop