Figure 2.1. Overview of the Spring Framework。The Spring Framework的20个模块能够被分红以下几类:Core Container, Data Access/Integration, Web, AOP (Aspect Oriented Programming), Instrumentation【仪器仪表】, Messaging, and Test类, as shown in the following diagram.html
Table:Spring framework的20个modules的artifactId,有了artifactId,就可使用项目管理工具(如maven/gradle等)来进行dependencies management了。这些module是相互独立的,能够任意引入其中的一个或多个module。java
org.springframework
.
GroupId | ArtifactId | Description |
---|---|---|
org.springframeworkweb |
spring-aopspring |
Proxy-based AOP support数据库 |
org.springframeworkexpress |
spring-aspectsbootstrap |
AspectJ based aspectsapi |
org.springframeworktomcat |
spring-beanswebsocket |
Beans support, including Groovy |
org.springframework |
spring-context |
Application context runtime, including scheduling and remoting abstractions |
org.springframework |
spring-context-support |
Support classes for integrating common third-party libraries into a Spring application context |
org.springframework |
spring-core |
Core utilities, used by many other Spring modules |
org.springframework |
spring-expression |
Spring Expression Language (SpEL) |
org.springframework |
spring-instrument |
Instrumentation agent for JVM bootstrapping |
org.springframework |
spring-instrument-tomcat |
Instrumentation agent for Tomcat |
org.springframework |
spring-jdbc |
JDBC support package, including DataSource setup and JDBC access support |
org.springframework |
spring-jms |
JMS support package, including helper classes to send and receive JMS messages |
org.springframework |
spring-messaging |
Support for messaging architectures and protocols |
org.springframework |
spring-orm |
Object/Relational Mapping, including JPA and Hibernate support |
org.springframework |
spring-oxm |
Object/XML Mapping |
org.springframework |
spring-test |
Support for unit testing and integration testing Spring components |
org.springframework |
spring-tx |
Transaction infrastructure, including DAO support and JCA integration |
org.springframework |
spring-web |
Web support packages, including client and web remoting |
org.springframework |
spring-webmvc |
REST Web Services and model-view-controller implementation for web applications |
org.springframework |
spring-webmvc-portlet |
MVC implementation to be used in a Portlet environment |
org.springframework |
spring-websocket |
WebSocket and SockJS implementations, including STOMP support |
spring-core
, spring-beans
, spring-context
, spring-context-support
, and spring-expression
这五个modulespring-core
,spring-context and spring-beans
modules 提供IoC功能和依赖注入功能,是the spring framework的基本功能模块,要想使用spring framework的beanfactory(其实是一个配置文件*.xml或者注解)来管理beans,就必需要引入20个module中的 The spring-core
and spring-beans
modules 。
org.springframework.beans
and org.springframework.context
packages are the basis for Spring Framework’s IoC container. 这些包中最主要的两个API是The BeanFactory
interface以及 ApplicationContext
interface,这两个接口都是用来管理beans的,建议使用 the ApplicationContext接口。BeanFactory
interface provides an advanced configuration mechanism capable of managing any type of object.org.springframework.context.ApplicationContext
is a sub-interface of BeanFactory
. It adds easier integration with Spring’s AOP features; message resource handling (for use in internationalization), event publication; and application-layer specific contexts such as the WebApplicationContext
for use in web applications. BeanFactory
provides the configuration framework and basic functionality, and the ApplicationContext
adds more enterprise-specific functionality.TheApplicationContext
is a complete superset of the BeanFactory
, the ApplicationContext
includes all functionality of the BeanFactory,因此
通常状况下咱们会使用 ApplicationContext interface,下面这个网址有使用ApplicationContext接口及其实现类管理beans的教程。固然,你也可使用beanFactory来管理你的beans,以下网址是使用BeanFactory接口管理beans的教程。(Spring官网建议使用the ApplicationContext
)spring-context
module
spring-core
and spring-beans 模块,
ApplicationContext
interface is the focal point of the Context module. spring-context-support
moduleprovides support for integrating common third-party libraries into a Spring application context for caching (EhCache, Guava, JCache), mailing (JavaMail), scheduling (CommonJ, Quartz) and template engines (FreeMarker, JasperReports, Velocity).spring-expression
module provides是JSP2.1规范中的表达式语言的一个扩展,你可使用表达式语言来setting and getting property values, property assignment, method invocation, accessing the content of arrays, collections and indexers, logical and arithmetic operators, named variables, and retrieval of objects by name from Spring’s IoC container. It also supports list projection and selection as well as common list aggregations.spring-aop
module提供AOP功能,spring-aspects
module provides integration with AspectJ【AspectJ:一个使用java语言编写的面向切面的框架】. spring-instrument
module provides class instrumentation support and classloader implementations to be used in certain application servers.spring-instrument-tomcat
module contains Spring’s instrumentation agent for Tomcat.spring-messaging
module to serve as a foundation for messaging-based applications. The module also includes a set of annotations for mapping messages to methods, similar to the Spring MVC annotation based programming model. The spring-jdbc
module provides a JDBC-abstraction【抽象】 layer that removes the need to do tedious 【单调乏味的】JDBC coding and parsing【解析】 of database-vendor【数据库供应商】 specific error codes.
The spring-tx
module supports programmatic and declarative transaction management for classes that implement special interfaces and for all your POJOs (Plain Old Java Objects).
The spring-orm
module provides integration layers for popular object-relational mapping APIs, including JPA, JDO, and Hibernate. Using the spring-orm
module you can use all of these O/R-mapping frameworks in combination with all of the other features Spring offers, such as the simple declarative transaction management feature mentioned previously.
The spring-oxm
module provides an abstraction layer that supports Object/XML mapping implementations such as JAXB, Castor, XMLBeans, JiBX and XStream.
The spring-jms
module (Java Messaging Service) contains features for producing and consuming messages. Since Spring Framework 4.1, it provides integration with the spring-messaging
module.
spring-web
, spring-webmvc
, spring-websocket
, and spring-webmvc-portlet
modules.spring-web
module provides basic web-oriented integration features such as多文件上传功能、初始化IoC 容器等功能(使用Servlet listeners以及面向web的application context来实现这些功能)。 It also contains an HTTP client and the web-related parts of Spring’s remoting support.The spring-webmvc
module (also known as the Web-Servlet module) 实现了MVC架构模式以及REST Web Services. Spring’s MVC framework provides a clean separation between domain model code and web forms and integrates with all of the other features of the Spring Framework.
The spring-webmvc-portlet
module (also known as the Web-Portlet module) provides the MVC implementation to be used in a Portlet environment and mirrors the functionality of the spring-webmvc
module.
spring-test
module supports the unit testing and integration testing of Spring components with JUnit or TestNG. It provides consistent loading of SpringApplicationContext
s and caching of those contexts. It also provides mock objects that you can use to test your code in isolation.
Figure 2.2. Typical full-fledged Spring web application
SessionFactory
configuration. Form controllers seamlessly integrate the web-layer with the domain model, removing the need for
ActionForms
or other classes that transform HTTP parameters to values for your domain model.
Figure 2.3. Spring middle-tier using a third-party web framework
ApplicationContext
and use a WebApplicationContext
to integrate your web layer.
Figure 2.5. EJBs - Wrapping existing POJOs
The Spring Framework also provides an access and abstraction layer for Enterprise JavaBeans, enabling you to reuse your existing POJOs and wrap them in stateless session beans for use in scalable, fail-safe web applications that might need declarative security.