「Spring认证」Spring 框架概述

分享 0 695
IT胶囊
IT胶囊 LV1 2021年8月12日 13:50 发表
点击群号免费加入社区交流群:367346704
<p style="margin-top: 0px; margin-bottom: 8px; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;">Spring 是最流行的企业 Java 应用程序开发框架。全球数以百万计的开发人员使用 Spring Framework 来创建高性能、易于测试和可重用的代码。</p><p style="margin-top: 0px; margin-bottom: 8px; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;">Spring 框架是一个开源的 Java 平台。它最初由 Rod Johnson 编写,并于 2003 年 6 月在 Apache 2.0 许可下首次发布。</p><p style="margin-top: 0px; margin-bottom: 8px; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;">在尺寸和透明度方面,Spring 是轻量级的。Spring 框架的基本版本大约为 2MB。</p><p style="margin-top: 0px; margin-bottom: 8px; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;">Spring Framework 的核心功能可用于开发任何 Java 应用程序,但有一些扩展可用于在 Java EE 平台之上构建 Web 应用程序。Spring 框架旨在通过启用基于 POJO 的编程模型使 J2EE 开发更易于使用并促进良好的编程实践。</p><h2 id="%E4%BD%BF%E7%94%A8-Spring-%E6%A1%86%E6%9E%B6%E7%9A%84%E5%A5%BD%E5%A4%84" name="%E4%BD%BF%E7%94%A8-Spring-%E6%A1%86%E6%9E%B6%E7%9A%84%E5%A5%BD%E5%A4%84" style="margin-top: 16px; margin-bottom: 8px; font-size: 16px; list-style: inherit; font-weight: bold; line-height: 26px; font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;">使用 Spring 框架的好处</h2><p style="margin-top: 0px; margin-bottom: 8px; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;">以下是使用 Spring Framework 的几个巨大好处的列表 -</p><ul style="margin-top: 0px; margin-bottom: 16px; margin-left: 0px; list-style: none; color: rgb(51, 51, 51); font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;"><li style="margin-bottom: 4px; padding-left: 18px; list-style-type: none; position: relative;">Spring 使开发人员能够使用 POJO 开发企业级应用程序。仅使用 POJO 的好处是您不需要 EJB 容器产品(如应用程序服务器),但您可以选择仅使用健壮的 servlet 容器(如 Tomcat 或某些商业产品)。</li><li style="margin-bottom: 4px; padding-left: 18px; list-style-type: none; position: relative;">Spring 以模块化方式组织。尽管包和类的数量很多,但您只需要担心您需要的包和类,而忽略其余的。</li><li style="margin-bottom: 4px; padding-left: 18px; list-style-type: none; position: relative;">Spring 并没有重新发明轮子,而是真正利用了一些现有技术,如几个 ORM 框架、日志框架、JEE、Quartz 和 JDK 计时器以及其他视图技术。</li><li style="margin-bottom: 4px; padding-left: 18px; list-style-type: none; position: relative;">测试用 Spring 编写的应用程序很简单,因为依赖于环境的代码被移到了这个框架中。此外,通过使用 JavaBeanstyle POJO,使用依赖注入来注入测试数据变得更加容易。</li><li style="margin-bottom: 4px; padding-left: 18px; list-style-type: none; position: relative;">Spring 的 web 框架是一个精心设计的 web MVC 框架,它提供了一个很好的替代 web 框架,如 Struts 或其他过度设计或不太流行的 web 框架。</li><li style="margin-bottom: 4px; padding-left: 18px; list-style-type: none; position: relative;">Spring 提供了一个方便的 API 来将特定于技术的异常(例如由 JDBC、Hibernate 或 JDO 抛出)转换为一致的、未经检查的异常。</li><li style="margin-bottom: 4px; padding-left: 18px; list-style-type: none; position: relative;">轻量级 IoC 容器往往是轻量级的,尤其是与 EJB 容器相比时。这有利于在内存和 CPU 资源有限的计算机上开发和部署应用程序。</li><li style="margin-bottom: 4px; padding-left: 18px; list-style-type: none; position: relative;">Spring 提供了一个一致的事务管理接口,可以缩小到本地事务(例如使用单个数据库)和扩展到全局事务(例如使用 JTA)。</li></ul><h2 id="%E4%BE%9D%E8%B5%96%E6%B3%A8%E5%85%A5-(DI)" name="%E4%BE%9D%E8%B5%96%E6%B3%A8%E5%85%A5-(DI)" style="margin-top: 16px; margin-bottom: 8px; font-size: 16px; list-style: inherit; font-weight: bold; line-height: 26px; font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;">依赖注入 (DI)</h2><p style="margin-top: 0px; margin-bottom: 8px; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;">Spring 最认同的技术是控制反转的<strong style="list-style: inherit;">依赖注入 (DI)</strong>风格。该<strong style="list-style: inherit;">控制反转(IOC)</strong>是一个笼统的概念,它可以在许多不同的方式来表达。依赖注入只是控制反转的一个具体例子。</p><p style="margin-top: 0px; margin-bottom: 8px; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;">在编写复杂的 Java 应用程序时,应用程序类应尽可能独立于其他 Java 类,以增加重用这些类的可能性,并在单元测试时独立于其他类进行测试。依赖注入有助于将这些类粘合在一起,同时保持它们的独立性。</p><p style="margin-top: 0px; margin-bottom: 8px; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;">究竟什么是依赖注入?我们分别看一下这两个词。这里的依赖部分转化为两个类之间的关联。例如,A 类依赖于 B 类。现在,让我们看看第二部分,注入。所有这些意味着,B 类将被 IoC 注入到 A 类中。</p><p style="margin-top: 0px; margin-bottom: 8px; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;">依赖注入可以通过将参数传递给构造函数的方式发生,也可以通过使用 setter 方法的后构造发生。由于依赖注入是 Spring Framework 的核心,我们将在单独的章节中用相关示例解释这个概念。</p><h2 id="%E9%9D%A2%E5%90%91%E6%96%B9%E9%9D%A2%E7%BC%96%E7%A8%8B-(AOP)" name="%E9%9D%A2%E5%90%91%E6%96%B9%E9%9D%A2%E7%BC%96%E7%A8%8B-(AOP)" style="margin-top: 16px; margin-bottom: 8px; font-size: 16px; list-style: inherit; font-weight: bold; line-height: 26px; font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;">面向方面编程 (AOP)</h2><p style="margin-top: 0px; margin-bottom: 8px; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;">Spring 的关键组件之一是<strong style="list-style: inherit;">面向方面的编程 (AOP)</strong>框架。跨越应用程序多个点的功能称为<strong style="list-style: inherit;">横切关注点</strong>,这些横切关注点在概念上与应用程序的业务逻辑分离。方面有各种常见的好例子,包括日志记录、声明性事务、安全性、缓存等。</p><p style="margin-top: 0px; margin-bottom: 8px; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;">OOP 中模块化的关键单位是类,而 AOP 中模块化的单位是方面。DI 帮助您将应用程序对象彼此分离,而 AOP 帮助您将横切关注点与它们影响的对象分离。</p><p style="margin-top: 0px; margin-bottom: 8px; list-style: inherit; min-height: 24px; color: rgb(51, 51, 51); font-family: &quot;pingfang SC&quot;, &quot;helvetica neue&quot;, arial, &quot;hiragino sans gb&quot;, &quot;microsoft yahei ui&quot;, &quot;microsoft yahei&quot;, simsun, sans-serif; white-space: pre-wrap;">Spring Framework 的 AOP 模块提供了一个面向方面的编程实现,允许您定义方法拦截器和切入点,以干净地解耦实现应该分离的功能的代码。我们将在单独的章节中讨论更多关于 Spring AOP 概念的内容。</p>
收藏(0)  分享
相关标签: Spring Spring认证 java
0个回复
  • 消灭零回复