春季框架
Spring Framework 是最流行的 Java EE 框架之一。在本文中,我们将学习以下内容:
- Spring framework architecture
- Core components of Spring
- Various projects under the spring framework umbrella.
我查看了Spring Framework,Servlet,JSP和JSF的Google趋势图表。很明显,Spring在所有其他Java EE技术中遥遥领先。

什么是Spring框架?
春天是Java企业版最受欢迎的框架之一。全世界的开发人员都使用Spring来开发可靠和高质量的应用程序。Spring框架是由Rod Johnson设计的。从那时起,Spring已成为Java世界中EJB模型的替代技术。使用Spring框架可以创建不同类型的应用程序。
Spring核心概念 – 依赖注入(DI)、控制反转(IoC)、面向切面编程(AOP)
- It is impossible to understand what is Spring Framework without understanding what is Dependency Injection and Inversion of Control. Dependency Injection also called as DI, is one of the types of Inversion of Control (IoC).
- Inversion of Control – this is the principle of object-oriented programming, in which objects of the program do not depend on concrete implementations of other objects, but may have knowledge about their abstractions (interfaces) for later interaction.
- Dependency Injection – is a composition of structural design patterns, in which for each function of the application there is one, a conditionally independent object (service) that can have the need to use other objects (dependencies) known to it by interfaces. Dependencies are transferred (implemented) to the service at the time of its creation. This is a situation where we introduce an element of one class into another. In practice, DI is implemented by passing parameters to the constructor or using setters. Libraries that implement this approach are also called IoC containers.
- Aspect oriented programming – a programming paradigm that allows you to distinguish cross-through (functional) functionality in application. These functions, which span multiple application nodes, are called cross-cutting concerns and these cross-cutting notes are separated from the immediate business logic of the application. In OOP, the key unit is the class, while in AOP, the key element is the aspect. DI helps to separate application classes into separate modules, and AOP helps to separate cross-cutting concerns from the objects they affect.
春季框架架构

Spring框架的核心组件
Spring的核心容器由四个模块组成:SpEL(Spring表达式语言)、Context(上下文)、Core(核心)、Beans(Bean)。对于这些元素的描述如下:
-
- SpEL模块为在执行期间操纵对象提供了强大的表达式语言。
-
- 上下文是基于Beans和Core构建的,允许您访问在设置中定义的任何对象。上下文模块的关键元素是ApplicationContext接口。
-
- Core模块提供了框架的关键部分,包括IoC和DI属性。
- Bean模块负责创建和管理Spring Beans – 是应用程序上下文的结构单元。
春天的框架网
Spring框架的网络层包括Web、Web-MVC、Web-Socket、Web-Portlet等组件。
-
- Web模块提供了下载文件、创建Web应用程序、REST Web服务等功能。
-
- Web-MVC包含了用于Web应用程序的Spring MVC实现。
-
- Web-Socket在Web应用程序中提供了客户端和服务器之间使用Web套接字进行通信的支持。
- Web-Portlet提供了在门户环境下的MVC实现。
春季框架数据访问
数据访问/集成容器包括 JDBC、ORM、OXM、JMS 和事务模块。
-
- JDBC提供了一个JDBC的抽象层,并且消除了开发者手动注册与数据库连接相关的单调代码的需要。
-
- Spring ORM提供了与流行的ORM(对象关系映射)工具,如Hibernate和JDO(Java数据对象),即JPA(Java持久化API)的实现的集成。
-
- OXM模块负责链接对象/ XML,如XMLBeans、JAXB等。
-
- JMS(Java消息服务)模块负责创建、发送和接收消息。
- Transactions为实现特定方法和POJO(普通的Java对象)的类提供事务管理支持。
杂项模块
春天还包括了一些其他重要的模块,比如AOP、Aspects、Instrumentation、Messaging和Test模块。
-
- AOP实现面向切面编程,并且可以利用AOP的全部功能。
-
- Aspects模块与AspectJ集成,也是一个强大的AOP框架。
-
- Instrumentation负责支持服务器应用中所使用的类注入和类加载器。
-
- Messaging模块提供STOMP支持。
- 最后,Test模块提供使用TestNG或JUnit框架进行测试。
Spring 5的特性
春季5版本对春季4带来了巨大的更新。春季5的一些重要功能有:
-
- 支持Java 8、Java 9、Java EE 7、Java EE 8、Servlet 4.0、Bean Validation 2.0和JPA 2.2。我很高兴看到Spring在努力迎头赶上正在使用的主要技术的最新版本。
-
- 通过新模块spring-jcl改进了日志记录。
-
- 文件操作使用NIO 2流,因此性能得到改善。
-
- 支持将Reactor 3.1 Flux和Mono以及RxJava 1.3和2.1作为Spring MVC控制器方法的返回值。
-
- 支持Kotlin、Project Lombok、JSON Binding API作为Jackson和GSON的替代方案。
-
- Spring WebFlux – Spring正在变得响应式。
-
- 支持JUnit 5。
- 通过Kotlin实现函数式编程支持。
你可以在我们的GitHub代码库上查看Spring项目。
参考资料:Spring 官方网站,Spring 参考文档