下载地址
SpringFramework下载地址:http://projects.spring.io/spring-framework/
SpringFramework Maven资源库地址:http://mvnrepository.com/search?q=spring
Spring Framework
企业应用开发的轻量级解决方案
提供了一站式编程的功能
组成Spring框架的每个模块(组间)都可以单独存在,或者与其他一个或者多个模块联合实现
Spring的设计是非入侵式的(non-intrusive):业务逻辑代码不会受限于框架本身
Spring Framework自2004年发布以来,中间经历了几个比较大的版本变化。
Spring 2.0 provided XML namespaces and AspectJ support;
Spring 2.5 embraced annotation-driven configuration;
Spring 3.0 introduced a strong Java 5+ foundation across the framework codebase, and
features such as the Java-based @Configuration model.
Spring 4.0 is the latest major release of the Spring Framework and the first to fully support Java 8 features.
Spring Framework由大约20个具有不同特征的模块组成
这些模块根据其功能分为不通的组
包括Core Container, Data Access/Integration, Web, AOP (Aspect Oriented Programming),
Instrumentation, Messaging, and Test。
Core Container
由spring-core, spring-beans, spring-context, springcontext-support, and spring-expression (Spring Expression Language)模块组成。
spring-core和spring-beans提供了 Spring 框架的基本功能,包括控制反转(Inversion of Control,简称IoC)和
依赖注入(Dependency Injection简称DI)的特性。核心容器的主要组件是 BeanFactory
,它是工厂模式的实现。
BeanFactory
将应用程序的配置和依赖性规范与实际的应用程序代码分开。
spring-context是一个配置文件,向 Spring 框架提供上下文信息。Spring 上下文包括企业服务,例如 JNDI、EJB、电子邮件、国际化、校验和调度功能。
spring-expression主要提供了spring的表达式语言(Expression Language),它是对标准EL的扩展。
AOP and Instrumentation
Spring AOP 模块直接将面向方面的编程功能集成到了 Spring 框架中。
单独的spring-aspects模块用来支持与AspectJ的集成。
spring-instrument模块提供在特定的应用程序服务器中类仪器支持和类加载器实现。
Messaging
Spring Framework 4引入的,主要用来实现基于消息(message)的应用程序开发。
Data Access/Integration
该层包括JDBC, ORM, OXM, JMS, and Transaction等模块,主要实现与持久层(如数据库)的连接及事务的控制,如spring-jdbc、spring-tx、spring-orm、spring-oxm、spring-jms。
从Spring Framework 4.1开始,spring-jms支持与spring-messaging进行集成。
Web
Web部分包括spring-web, spring-webmvc, spring-websocket, and springwebmvc-
portlet几个模块。
spring-web模块提供了基本的面向web的开发特性,如多文件上传功能、通过Servlet监听和基于web的应用程序上下文初始化IoC等。
spring-webmvc包括Spring MVC模型及Web应用开发中REST风格的Web Service实现。
spring-webmvc-portlet提供了门户导入的组件信息支持,注意ModelAndView在该包和webmvc包都存在,在使用SpringMVC时需要注意,不用引入错了。
Test
Spring测试功能模块支持。
2、Spring MVC
Spring框架提供了构建Web应用程序的全功能MVC模块,叫Spring MVC,通过Spring Core+Spring MVC即可搭建一套稳定的Java Web项目。
Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动(请求-响应模型)类型的轻量级Web 框架,将web 层进行职责解耦。
Tomcat服务器启动入口文件是web.xml,通过在其中配置相关的Listener和Servlet即可加载Spring MVC所需数据。
<!-- 加载Spring配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext.xml</param-value>
</context-param>
<listener>
<description>Spring Listener</description>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 加载spring mvc配置信息 -->
<!-- DispatcherServlet load spring mvc config file -->
<servlet>
<description>spring mvc servlet</description>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<description>spring mvc config file</description>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
ContextLoaderListener监听器的作用就是启动Web容器时,自动装配ApplicationContext的配置信息。因为它实现了ServletContextListener这个接口,在web.xml配置这个监听器,启动容器时,就会默认执行它实现的方法。
org.springframework.web.context.ContextLoaderListener
extends org.springframework.web.context.ContextLoader
implements javax.servlet.ServletContextListener
extends servlet.ServletContextListener extends java.util.EventListener
说明:Spring框架本身的配置文件applicationContext.xml由ContextLoader来加载
DispatcherServlet是HTTP请求处理与控制的中心调度器,调度器注册处理器(handler)来处理web请求、提供方便的映射(mapping)和异常(exception)处理功能。
org.springframework.web.servlet.DispatcherServlet
extends org.springframework.web.servlet.FrameworkServlet
extends org.springframework.web.servlet.HttpServletBean
extends javax.servlet.http.HttpServlet
extends javax.servlet.GenericServlet
implements Servlet, ServletConfig, java.io.Serializable
implements org.springframework.context.ApplicationContextAware
说明:SpringMVC框架的配置文件由FrameworkServlet来加载。
Spring简单介绍:https://blog.51cto.com/luchunli/1711309