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.