org.springframework – org.springframework

最后修改: 2016年 11月 13日

中文/混合/英文(键盘快捷键:t)

1. Introduction

1.介绍

The Spring Framework provides a clean and expressive programming and configuration model for modern Java-based enterprise applications that can run on any deployment platform.

Spring框架为可以在任何部署平台上运行的基于Java的现代企业应用程序提供了一个简洁而富有表现力的编程和配置模型。

This article covers the high-level overview of the Spring framework and mainly, the org.springframework package which provides support for dependency injection, transaction management, web applications, data access, messaging, testing and more.

本文介绍了Spring框架的高层概述,主要是org.springframework包,它为依赖注入、事务管理、Web应用程序、数据访问、消息传递、测试等提供支持。

2. Features

2.特点

Spring framework offers a comprehensive list of features:

Spring框架提供了一个全面的功能列表。

  • Spring MVC web application and RESTful web service framework
  • Aspect-Oriented Programming including Spring’s declarative transaction management
  • Dependency Injection
  • Inversion of Control

and much more.

以及更多。

3. Maven Dependencies

3.Maven的依赖性

If you want to add Spring to your Maven project, you can find more information about it here.

如果你想在你的Maven项目中加入Spring,你可以在这里找到更多相关信息

4. Spring Projects

4.Spring项目

The Framework includes a number of different modules and projects. From configuration to security, web apps to big data – whatever the infrastructure needs of your application may be, there is a Spring Project to help you build it.

该框架包括许多不同的模块和项目。从配置到安全,从网络应用到大数据–无论你的应用程序的基础设施需求是什么,都有一个Spring项目来帮助你建立它。

Start small and use just what you need – Spring is modular by design. Let’s look at some of those projects here.

从小处着手,只使用你需要的东西–Spring的设计是模块化的。让我们在这里看看这些项目中的一些。

4.1. Spring Web MVC

4.1.Spring Web MVC

Web MVC framework provides Model-View-Controller architecture, designed around a DispatcherServlet which handles all the HTTP requests and responses and makes the application loosely coupled.

Web MVC框架提供了模型-视图-控制器架构,围绕DispatcherServlet设计,处理所有的HTTP请求和响应,使应用程序松散耦合。

The best thing about it is it allows you to use any object as a command or form object – there is no need to implement a framework-specific interface or base class. Its data binding is highly flexible: for example, it treats type mismatches as validation errors that can be evaluated by the application, not as system errors.

它最好的一点是允许你使用任何对象作为命令或表单对象–不需要实现框架特定的接口或基类。它的数据绑定非常灵活:例如,它将类型不匹配视为可由应用程序评估的验证错误,而不是系统错误。

Here you can find the complete guide.

在这里你可以找到完整的指南

4.2. Spring IO Platform

4.2.Spring IO平台[/strong]

IO Platform defines a set of dependencies (both Spring Framework dependencies as third-party libraries) that could be included on a Java project to allow you to choose the necessary dependencies without worrying about compatibility between their versions (because Spring IO guarantees it).

IO平台定义了一组可以包含在Java项目中的依赖关系(包括Spring框架依赖关系和第三方库),以便您可以选择必要的依赖关系,而不必担心其版本之间的兼容性(因为Spring IO保证)。

The IO Platform is certified to work with Java 7 and 8.

IO平台经认证可与Java 7和8一起使用。

Have a look at the GitHub project.

请看一下GitHub项目

4.3. Spring Boot

4.3.Spring布特

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. It makes it very easy to create a Spring-powered application with a minimum of work.

Spring Boot使您能够轻松地创建独立的、基于生产级别的Spring应用程序,您可以 “直接运行”。它使创建一个由Spring驱动的应用程序变得非常容易,只需做少量的工作。

An application created with it can be largely autoconfigured with some sensible defaults and next to that can be improved with metrics (how many requests, how long did requests take etc.).

用它创建的应用程序在很大程度上可以通过一些合理的默认值进行自动配置,接下来可以通过指标(有多少个请求,请求花了多长时间等)来改进。

It consists of several (optional) modules:

它由几个(可选)模块组成。

  1. CLI – A command line interface, based on Groovy, to start/stop spring boot created applications.
  2. Boot Core – The base for other modules.
  3. Auto-configure – Module to auto-configure a wide range of Spring projects. It will detect an availability of certain frameworks (Spring Batch, Spring Data JPA, Hibernate, JDBC).
  4. Actuator – This project, when added, will enable certain enterprise features (Security, Metrics, Default Error pages) to your application.
  5. Starters – Different quickstart projects to include as a dependency in your Maven or Gradle build file. It will have the needed dependencies for that type of application. Currently, there are starter projects for a web project (tomcat and jetty based), Spring Batch, Spring Data JPA, Spring Integration, Spring Security exist.
  6. Tools – The Maven and Gradle build tool as well as the custom Spring Boot Loader (used in the single executable jar/war) is included in this project.

We can find the Maven artifact here and have a look at the GitHub project.

我们可以在这里找到Maven工件,并看看GitHub项目

4.4. Spring Data

4.4.Spring的数据

Spring Data’s mission is to provide a familiar and consistent, Spring-based programming model for data access while still retaining the special traits of the underlying data store.

Spring Data的使命是为数据访问提供熟悉和一致的、基于Spring的编程模型,同时仍然保留底层数据存储的特殊特征。

The primary goal of this project is to make it easier to build Spring-powered applications that use new data access technologies such as non-relational databases, map-reduce frameworks, and cloud based data services as well as provide improved support for relational database technologies.

这个项目的主要目标是使其更容易建立由Spring驱动的应用程序,这些应用程序使用新的数据访问技术,如非关系型数据库、地图还原框架和基于云的数据服务,并提供对关系型数据库技术的改进支持。

This is an umbrella project which contains many sub-projects that are specific to a given database (like JPA, MongoDB, Redis, Apache Solr, Gemfire, Apache Cassandra). The projects are developed by working together with many of the companies and developers that are behind these exciting technologies.

这是一个伞形项目,其中包含许多针对特定数据库的子项目(如JPAMongoDBRedisApache SolrGemfireApache Cassandra)。这些项目是通过与这些令人兴奋的技术背后的许多公司和开发人员合作开发的。

4.5. Spring Security

4.5.Spring的安全性

Spring Security is a framework that focuses on providing both authentication and authorization to Java applications. Like all Spring projects, the real power of Spring Security is found in how easily it can be extended to meet custom requirements. It is released under an Apache 2.0 license so you can confidently use it in your projects.

Spring Security是一个框架,它专注于为Java应用程序提供认证和授权。与所有Spring项目一样,Spring Security的真正力量在于它可以很容易地进行扩展以满足客户的需求。它是根据Apache 2.0许可证发布的,因此您可以放心地在您的项目中使用它。

It is also easy to learn, deploy and manage. It has dedicated security namespace which provides directives for most common operations, allowing complete application security in just a few lines of XML and can protect your apps against attacks like session fixation, clickjacking, cross-site request forgery, etc.

它也很容易学习、部署和管理。它有专门的安全命名空间,为大多数常见的操作提供指令,只需几行XML就可以实现完整的应用安全,可以保护你的应用免受攻击,如会话固定、点击劫持、跨站请求伪造等。

Spring Security is also integrated with many other Spring technologies, including Spring Web Flow, Spring Web Services and Pivotal tc Server.

Spring Security还与许多其他Spring技术集成,包括Spring Web Flow、Spring Web Services和Pivotal tc Server。

Do have a look at the FAQs of Spring security to have a deeper insight and the Maven dependency page. Also, have a look at Spring security tutorials for Authentication, Registration, and setup Spring Security with Maven.

请看一下Spring安全的FAQs,以获得更深入的了解,以及Maven依赖性页面。此外,请看Spring安全教程,包括AuthenticationRegistration,以及setup Spring Security with Maven

4.6. Spring Social

4.6.Spring社会活动

Spring Social is an extension of the framework that enables applications to connect with Software-as-a-Service providers such as Twitter, Facebook, and other OAuth authentication based APIs. It provides a ready to use OAuth authentication framework for web based applications.

Spring Social是该框架的一个扩展,使应用程序能够与软件即服务提供者(如Twitter、Facebook和其他OAuth认证的API)进行连接。它为基于Web的应用程序提供了一个可随时使用的OAuth认证框架。

Features:

  • An extensible service provider framework that greatly simplifies the process of connecting local user accounts to hosted provider accounts.
  • A connect controller that handles the authorization flow between your Java/Spring web application, a service provider, and your users.
  • Java bindings to popular service provider APIs such as Facebook, Twitter, LinkedIn, TripIt, and GitHub.
  • A sign-in controller that enables users to authenticate with your application by signing in through a service provider.

Getting Started Guides:

Spring provides quite a few examples of GitHub projects to make you start quickly and Spring Social reference is handy as well with a quick start page.

Spring提供了相当多的GitHub项目的例子,使你能够快速入门,Spring社会参考也很方便,有快速入门页面。

4.7. Spring Shell

4.7.Spring的外壳

Spring Shell is an interactive shell that can be easily extended with commands using a Spring based programming model.

Spring Shell是一个交互式的外壳,可以使用基于Spring的编程模型轻松扩展命令。

Users of the shell project can easily build a full featured shell (aka command line) application by depending on the Spring Shell jar and adding their own commands (which come as methods on spring beans). Creating a command line application can be useful e.g. to interact with your project’s REST API, or to work with local file content.

Shell项目的用户可以通过依赖Spring Shell jar和添加他们自己的命令(作为spring beans的方法),轻松建立一个全功能的shell(aka命令行)应用程序。创建一个命令行应用程序对于e.g.与你的项目的REST API进行交互,或者与本地文件内容进行交互是非常有用的。

The GitHub project can be found here.

GitHub项目可以在这里找到。

4.8. Spring Mobile

4.8.Spring行动

Spring Mobile is an extension of the framework and Spring Web MVC that aims to simplify the development of mobile web applications.

Spring Mobile是该框架和Spring Web MVC的扩展,旨在简化移动Web应用程序的开发。

Spring Mobile is a framework that provides capabilities to detect the type of device making a request to your Spring website and serve alternative views based on that device. Like all Spring projects, the real power of Spring Mobile is found in how easily it can be extended.
Features:

Spring Mobile是一个框架,它提供了检测向你的Spring网站发出请求的设备类型的功能,并根据该设备提供替代视图。像所有的Spring项目一样,Spring Mobile的真正威力在于它可以很容易地被扩展。
特点。

  • A Device resolver abstraction for server-side detection of mobile and tablet devices
  • Site preference management that allows the user to indicate if he or she prefers a “normal”, “mobile”, or “tablet” experience
  • A site switcher capable of switching the user to the most appropriate site, either mobile, tablet or normal, based on his or her device and optionally indicated a site preference
  • Device aware view management for organizing and managing different views for specific devices.

This sample application will get you started quickly.

这个示例应用程序将让你快速入门。

You can also detect a device, handle a website preference or serve mobile web content with Spring MVC.

您还可以检测设备、处理网站偏好或使用Spring MVC服务移动Web内容。

4.9. Spring Batch

4.9.Spring批处理

Spring Batch is a lightweight, comprehensive framework aimed at enabling the development of batch applications vital for the daily operations of enterprise systems.

Spring Batch是一个轻量级的综合框架,旨在支持开发对企业系统的日常运作至关重要的批处理应用程序。

Batch applications in this context refer to automated offline systems targeted towards bulk data processing. Spring Batch automates this basic batch iteration, providing the capability to process similar transactions as a set, typically in an offline environment without any user interaction.

批量应用在这里指的是针对批量数据处理的自动化离线系统。Spring Batch将这种基本的批量迭代自动化,提供了将类似交易作为一个集合进行处理的能力,通常是在离线环境下,无需任何用户互动。

Spring Batch works by reading data with a configurable chunk size from a data source, process it and finally write it to a resource.

Spring Batch的工作方式是,从数据源读取具有可配置块大小的数据,对其进行处理,最后将其写入资源中。

The data source for the reader can be flat files (text file, XML file, CSV file…), relational database (MySQL…), MongoDB.
Similarly, a writer can write data to flat files, relational databases, MongoDB, mailer etc.

读者的数据源可以是平面文件(文本文件、XML文件、CSV文件…)、关系数据库(MySQL…)、MongoDB。
同样,写作者可以将数据写到平面文件、关系数据库、MongoDB、mailer等。

Get started quickly by Creating a Batch Service and with other Spring batch resources.

通过创建批处理服务和其他Spring批处理资源快速入门。

5. Core Spring Packages

5.核心Spring包

Here, let’s take a look at core Spring packages.

在这里,让我们来看看核心的Spring包。

This list is limited and just describes core packages for Spring framework. You can find the complete listing here.

这个列表是有限的,只是描述了Spring框架的核心包。你可以找到完整的列表这里

6. Conclusion

6.结论

In this quick overview article, we had a look at various projects which are present in Spring ecosystem and made a rich collection of Maven dependencies, the GitHub projects, and the comprehensive features each project offers to make our web apps secure, scalable and easy to live with.

在这篇快速概览文章中,我们了解了Spring生态系统中的各种项目,并收集了丰富的Maven依赖项、GitHub项目以及每个项目提供的综合功能,使我们的Web应用安全、可扩展且易于使用。

We also had a look at core packages which provide us power to focus on a logical aspect of our apps.

我们还看了一下核心软件包,它为我们提供了专注于我们应用程序的逻辑方面的能力。