Spring Framework 5.0.0.M3中文文檔 翻譯記錄 Part I. Spring框架概覽1-2.2

Part I. Spring框架概覽

The Spring Framework is a lightweight solution and a potential one-stop-shop for building your enterprise-ready applications. However, Spring is modular, allowing you to use only those parts that you need, without having to bring in the rest. You can use the IoC container, with any web framework on top, but you can also use only theHibernate integration code or the JDBC abstraction layer. The Spring Framework supports declarative transaction management, remote access to your logic through RMI or web services, and various options for persisting your data. It offers a full-featured MVC framework, and enables you to integrate AOP transparently into your software.html

Spring Framework是一種輕量級的解決方案,是構建你的企業級應用程序的潛在一站式解決方案。 儘管如此,Spring是模塊化的,容許你只使用你須要的那些部分,而沒必要引入其餘的。 你可使用IoC容器,任何Web框架在頂部(只是底層用Spring框架,好比ssh,中間那層用了Spring),但你也能夠只使用Hibernate集成代碼或JDBC抽象層。 Spring框架支持聲明式事務管理,經過RMI或Web服務遠程訪問你的邏輯,以及用於持久存儲數據的各類選項。 它提供了一個全功能的MVC框架,並使你可以將AOP透明地集成到你的軟件中。git

Spring is designed to be non-intrusive, meaning that your domain logic code generally has no dependencies on the framework itself. In your integration layer (such as the data access layer), some dependencies on the data access technology and the Spring libraries will exist. However, it should be easy to isolate these dependencies from the rest of your code base.程序員

Spring設計爲非侵入式的,這意味着你所寫的邏輯代碼一般沒有對框架自己的依賴。 在你的集中處理層(例如數據訪問層)中,將存在對數據訪問技術和Spring庫的一些依賴。 可是,應該很容易將這些依賴關係與其他代碼庫隔離開。web

This document is a reference guide to Spring Framework features. If you have any requests, comments, or questions on this document, please post them on the user mailing list. Questions on the Framework itself should be asked on StackOverflow (see https://spring.io/questions).spring

本文檔是Spring Framework特性的參考指南。 若是你對本文檔有任何要求,意見或問題,請將其張貼在用戶郵件列表中。 框架自己的問題應該在StackOverflow(請參閱https://spring.io/questions)。數據庫

1. Spring入門

This reference guide provides detailed information about the Spring Framework. It provides comprehensive documentation for all features, as well as some background about the underlying concepts (such as "Dependency Injection") that Spring has embraced.express

本參考指南提供了有關Spring框架的詳細信息。 它提供了全部功能的全面文檔,以及Spring所擁有的基本概念(例如「依賴注入」)的一些背景知識。編程

If you are just getting started with Spring, you may want to begin using the Spring Framework by creating a Spring Boot based application. Spring Boot provides a quick (and opinionated) way to create a production-ready Spring based application. It is based on the Spring Framework, favors convention over configuration, and is designed to get you up and running as quickly as possible.設計模式

若是你剛剛開始使用Spring,你可能想要經過建立一個基於Spring Boot的應用程序來開始使用Spring FrameworkSpring Boot提供了一種快速(和建議性)的方式來建立基於生產環境的Spring應用程序。 它是基於Spring框架,喜歡約定的配置,而且旨在讓你快速啓動和運行。api

You can use start.spring.io to generate a basic project or follow one of the "Getting Started" guides like the Getting Started Building a RESTful Web Service one. As well as being easier to digest, these guides are very task focused, and most of them are based on Spring Boot. They also cover other projects from the Spring portfolio that you might want to consider when solving a particular problem.

你可使用start.spring.io來生成基本項目,或者按照「入門」指南之一,就像開始構建RESTful Web服務同樣。 除了更容易理解消化,這些指南是很是專一於任務,其中大部分都是基於Spring Boot。 它們還涵蓋了Spring解決特定問題時可能須要考慮的Spring組合中的其餘項目。

2.Spring框架簡介

The Spring Framework is a Java platform that provides comprehensive infrastructure support for developing Java applications. Spring handles the infrastructure so you can focus on your application.

Spring Framework是一個Java平臺框架,它爲開發Java應用程序的全面的基礎架構支持。Spring處理基礎架構,以便你能夠專一於應用程序。

Spring enables you to build applications from "plain old Java objects" (POJOs) and to apply enterprise services non-invasively to POJOs. This capability applies to the Java SE programming model and to full and partial Java EE.

Spring使你可以從「普通舊Java對象」(POJO)構建應用程序,並將企業服務非侵入性地應用於POJO。 此功能適用於Java SE編程模型和完整和部分Java EE

Examples of how you, as an application developer, can benefit from the Spring platform:

  • Make a Java method execute in a database transaction without having to deal with transaction APIs.
  • Make a local Java method a remote procedure without having to deal with remote APIs.
  • Make a local Java method a management operation without having to deal with JMX APIs.
  • Make a local Java method a message handler without having to deal with JMS APIs.

做爲應用程序開發人員,你能夠如何從Spring平臺中受益的示例:

  • 在數據庫事務中執行Java方法,而沒必要處理事務API。
  • 使本地Java方法成爲遠程過程,而沒必要處理遠程API。(意思就是無須管相關的遠程調用api,Spring已經封裝好了,你本身只須要專一本身的邏輯便可,下同,再也不解釋)
  • 使本地Java方法成爲管理操做,而沒必要處理JMX API。
  • 使本地Java方法成爲消息處理程序,而沒必要處理JMS API。

2.1 依賴注入和控制反轉

A Java application — a loose term that runs the gamut from constrained, embedded applications to n-tier, server-side enterprise applications — typically consists of objects that collaborate to form the application proper. Thus the objects in an application have dependencies on each other.

Java應用程序 - 一個寬鬆的術語,其運行範圍從受限的嵌入式應用程序到n層,服務器端企業應用程序 - 一般由協做造成應用程序的對象組成。 所以,在一個應用程序中的對象具備關於彼此的依賴性。

Although the Java platform provides a wealth of application development functionality, it lacks the means to organize the basic building blocks into a coherent whole, leaving that task to architects and developers. Although you can use design patterns such as FactoryAbstract FactoryBuilderDecorator, and Service Locator to compose the various classes and object instances that make up an application, these patterns are simply that: best practices given a name, with a description of what the pattern does, where to apply it, the problems it addresses, and so forth. Patterns are formalized best practices that you must implement yourself in your application.

儘管Java平臺提供了豐富的應用程序開發功能,但它缺少將基本構建塊組織成一個總體的手段,將該任務留給架構師和開發人員。雖然可使用設計模式,例如工廠,抽象工廠,建築模式,裝飾器和服務定位器等設計模式來組成構成應用程序的各類類和對象實例,這些模式是:最佳實踐給出一個名字,有什麼模式的描述,如何應用它,它解決的問題,等等。 模式是形式化的最佳實踐,你必須在應用程序中實現本身。

The Spring Framework Inversion of Control (IoC) component addresses this concern by providing a formalized means of composing disparate components into a fully working application ready for use. The Spring Framework codifies formalized design patterns as first-class objects that you can integrate into your own application(s). Numerous organizations and institutions use the Spring Framework in this manner to engineer robust, maintainable applications.

Spring框架控制反轉(IoC)組件經過提供一種形式化的手段將不一樣的組件組成一個徹底可用的應用程序來解決這個問題。 Spring框架將形式化的設計模式編譯爲能夠集成到本身的應用程序中的第一類對象。 許多組織和機構以這種方式使用Spring框架來設計強大的,可維護的應用程序。(就是將各類設計模式融合到框架中,而開發人員只須要關注本身的邏輯,在不知不覺中就已經用到了最佳的設計模式,本身的代碼也得以健壯)

背景

"The question is, what aspect of control are [they] inverting?" Martin Fowler posed this question about Inversion of Control (IoC) on his site in 2004. Fowler suggested renaming the principle to make it more self-explanatory and came up with Dependency Injection.

「如今的問題是,什麼方面的控制是(他們)反轉?」 Martin Fowler在2004年在他的網站上提出了關於反轉控制(IoC)的問題.Fowler建議重命名這個原則,使其更一目瞭然,並提出依賴注入。

2.2 Modules

The Spring Framework consists of features organized into about 20 modules. These modules are grouped into Core Container, Data Access/Integration, Web, AOP (Aspect Oriented Programming), Instrumentation, Messaging, and Test, as shown in the following diagram.

Spring框架由大約20個功能模塊組成。 這些模塊分爲核心容器,數據訪問/集成,Web,AOP(面向方面的編程),儀器,消息傳遞和測試,以下圖所示。

圖2.1 Spring框架的概述

spring overview

The following sections list the available modules for each feature along with their artifact names and the topics they cover. Artifact names correlate to artifact IDs used in Dependency Management tools.

如下部分列出了每一個功能的可用模塊及其構件名稱及其涵蓋的主題。 構件名稱與構件關聯id用於管理工具的依賴。

2.2.1 Core Container

The Core Container consists of the spring-corespring-beansspring-contextspring-context-support, and spring-expression (Spring Expression Language) modules.

The spring-core and spring-beans modules provide the fundamental parts of the framework, including the IoC and Dependency Injection features. TheBeanFactory is a sophisticated implementation of the factory pattern. It removes the need for programmatic singletons and allows you to decouple the configuration and specification of dependencies from your actual program logic.

核心容器由spring-corespring-beansspring-contextspring-context-supportspring-expression(Spring Expression Language)模塊組成。

spring-corespring-beans模塊提供了框架的基本部分,包括IoC和依賴注入功能。 BeanFactory是一個複雜的工廠模式的實現。 它消除了編程單例的須要(程序員沒必要對單例親力親爲),並容許你從實際的程序邏輯中分離依賴性的配置和規範。

The Context (spring-context) module builds on the solid base provided by the Core and Beans modules: it is a means to access objects in a framework-style manner that is similar to a JNDI registry. The Context module inherits its features from the Beans module and adds support for internationalization (using, for example, resource bundles), event propagation, resource loading, and the transparent creation of contexts by, for example, a Servlet container. The Context module also supports Java EE features such as EJB, JMX, and basic remoting. The ApplicationContext interface is the focal point of the Context module. spring-context-support provides support for integrating common third-party libraries into a Spring application context, in particular for caching (EhCache, JCache) and scheduling (CommonJ, Quartz).

Context(spring-context)模塊創建在Core和Beans模塊提供的實體基礎之上:它是一種以相似於JNDI註冊表的框架樣式方式訪問對象的手段。 Context模塊Beans模塊繼承其特性,並增長了對國際化(例如使用資源束),事件傳播,資源加載以及經過例如Servlet容器的透明建立上下文的支持。 Context模塊還支持Java EE功能,如EJBJMX和基本遠程處理。ApplicationContext接口是Context模塊的焦點。spring-context-support提供支持將常見的第三方庫集成到Spring應用程序上下文中,特別是用於緩存(EhCacheJCache)和調度(CommonJQuartz)。

The spring-expression module provides a powerful Expression Language for querying and manipulating an object graph at runtime. It is an extension of the unified expression language (unified EL) as specified in the JSP 2.1 specification. The language supports 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-expression模塊提供了一個強大的表達式語言,用於在運行時查詢和操做對象圖。 它是JSP 2.1規範中規定的統一表達式語言(統一EL)的擴展。 該語言支持設置和獲取屬性值,屬性賦值,方法調用,訪問數組的內容,集合和索引器,邏輯和算術運算符,命名變量,以及經過Spring IoC容器中的名稱檢索對象。 它還支持列表投影和選擇以及公共列表聚合。

2.2.2 AOP and Instrumentation

The spring-aop module provides an AOP Alliance-compliant aspect-oriented programming implementation allowing you to define, for example, method interceptors and pointcuts to cleanly decouple code that implements functionality that should be separated. Using source-level metadata functionality, you can also incorporate behavioral information into your code, in a manner similar to that of .NET attributes.

The separate spring-aspects module provides integration with AspectJ.

The spring-instrument module provides class instrumentation support and classloader implementations to be used in certain application servers. The spring-instrument-tomcat module contains Spring’s instrumentation agent for Tomcat.

spring-aop模塊提供了一個符合AOP Alliance-compliant的面向方面的編程實現,容許你定義例如方法攔截器和切入點來乾淨地解耦實現應該分離的功能的代碼。 使用源代碼級元數據功能,你還能夠以相似於.NET屬性的方式將行爲信息合併到代碼中。

單獨的spring-aspects模塊提供與AspectJ的集成。

spring-instrument-tomcat 模塊提供類儀器支持和類加載器實現以在某些應用服務器中使用。 spring-instrument-tomcat模塊包含SpringTomcat的工具代理。

2.2.3 Messaging

Spring Framework 4 includes a spring-messaging module with key abstractions from the Spring Integration project such as MessageMessageChannelMessageHandler, and others 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.

 Spring Framework 4 包括一個 Spring消息傳遞模塊 ,從 Spring 集成項目中抽象出來,好比 Message, MessageChannel, MessageHandler 及其餘用來提供基於消息的基礎服務。 用做基於消息傳遞的應用程序的基礎 。 該模塊還包括一組用於將消息映射到方法的註解,相似於基於 Spring MVC 註解的編程模型。

2.2.4 Data Access/Integration 數據訪問/集成

The Data Access/Integration layer consists of the JDBC, ORM, OXM, JMS, and Transaction modules.

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 and Hibernate. Using the spring-orm module you can use 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, 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.

數據訪問/集成層由JDBC,ORM,OXM,JMS和Transaction 模塊組成。

spring-jdbc模塊提供了一個JDBC抽象層,消除了對繁瑣的JDBC編碼和解析數據庫供應商特定的錯誤代碼的須要。

spring-tx模塊支持實現特殊接口的類以及全部POJO(普通Java對象)的編程和聲明事務管理。

spring-orm模塊爲流行的對象關係映射API提供集成層,包括JPA和Hibernate。使用spring-orm模塊,你可使用這些O / R映射框架結合Spring提供的全部其餘功能,例如前面提到的簡單聲明式事務管理功能。

spring-oxm模塊提供了一個支持對象/ XML映射實現的抽象層,例如JAXB,Castor,JiBX和XStream。

spring-jms模塊(Java消息服務)包含用於生成和使用消息的功能。從Spring Framework 4.1開始,它提供了與spring-messaging模塊的集成。

2.2.5 Web

The Web layer consists of the spring-webspring-webmvc and spring-websocket modules.

The spring-web module provides basic web-oriented integration features such as multipart file upload functionality and the initialization of the IoC container using Servlet listeners and a web-oriented 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) contains Spring’s model-view-controller (MVC) and REST Web Services implementation for web applications. 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.

Web層由spring-webspring-webmvcspring-websocket模塊組成。(注:這裏和4的文檔比少了spring-webmvc-portlet模塊)

spring-web模塊提供基本的面向Web的集成功能,例如多部分文件上傳功能和使用Servlet偵聽器和麪向Web的應用程序上下文來初始化IoC容器。 它還包含一個HTTP客戶端和Web的相關部分的Spring的遠程支持。

spring-webmvc模塊(也稱爲Web-Servlet模塊)包含用於Web應用程序的Spring的模型視圖控制器(MVC)和REST Web服務實現。 SpringMVC框架提供了domain model(領域模型)代碼和Web表單之間的清晰分離,而且集成了Spring Framework 全部的其餘功能。

2.2.6 Test

The spring-test module supports the unit testing and integration testing of Spring components with JUnit or TestNG. It provides consistent loading of SpringApplicationContexts and caching of those contexts. It also provides mock objects that you can use to test your code in isolation.

spring-test模塊支持使用JUnitTestNGSpring組件進行單元測試和集成測試。 它提供了SpringApplicationContexts的一致加載和這些上下文的緩存。 它還提供了 mock objects(模擬對象),你可使用它來單獨測試你的代碼。

以爲看着彆扭的能夠查看本人Gitbook :https://muyinchen.gitbooks.io/spring-framework-5-0-0-m3/content/

相關文章
相關標籤/搜索