登录

  • 登录
  • 忘记密码?点击找回

注册

  • 获取手机验证码 60
  • 注册

找回密码

  • 获取手机验证码60
  • 找回
毕业论文网 > 外文翻译 > 计算机类 > 软件工程 > 正文

Spring框架介绍外文翻译资料

 2023-02-24 11:02  

Introducing the Spring Framework

The Spring Framework: a popular open source application framework that addresses many of the issues outlined in this book. This chapter will introduce the basic ideas of Spring and dis-cuss the central “bean factory” lightweight Inversion-of-Control (IoC) container in detail.

Spring makes it particularly easy to implement lightweight, yet extensible, J2EE archi-tectures. It provides an out-of-the-box implementation of the fundamental architectural building blocks we recommend. Spring provides a consistent way of structuring your applications, and provides numerous middle tier features that can make J2EE development significantly easier and more flexible than in traditional approaches.

The basic motivations for Spring are:

To address areas not well served by other frameworks. There are numerous good solutions to specific areas of J2EE infrastructure: web frameworks, persistence solutions, remoting tools, and so on. However, integrating these tools into a comprehensive architecture can involve significant effort, and can become a burden. Spring aims to provide an end-to-end solution, integrating spe-cialized frameworks into a coherent overall infrastructure. Spring also addresses some areas that other frameworks donrsquo;t. For example, few frameworks address generic transaction management, data access object implementation, and gluing all those things together into an application, while still allowing for best-of-breed choice in each area. Hence we term Spring an application framework, rather than a web framework, IoC or AOP framework, or even middle tier framework.

To allow for easy adoption. A framework should be cleanly layered, allowing the use of indi-vidual features without imposing a whole world view on the application. Many Spring features, such as the JDBC abstraction layer or Hibernate integration, can be used in a library style or as part of the Spring end-to-end solution.

To deliver ease of use. As wersquo;ve noted, J2EE out of the box is relatively hard to use to solve many common problems. A good infrastructure framework should make simple tasks simple to achieve, without forcing tradeoffs for future complex requirements (like distributed transactions) on the application developer. It should allow developers to leverage J2EE services such as JTA where appropriate, but to avoid dependence on them in cases when they are unnecessarily complex.

To make it easier to apply best practices. Spring aims to reduce the cost of adhering to best practices such as programming to interfaces, rather than classes, almost to zero. However, it leaves the choice of architectural style to the developer.

Non-invasiveness. Application objects should have minimal dependence on the framework. If leveraging a specific Spring feature, an object should depend only on that particular feature, whether by implementing a callback interface or using the framework as a class library. IoC and AOP are the key enabling technologies for avoiding framework dependence.

Consistent configuration. A good infrastructure framework should keep application configuration flexible and consistent, avoiding the need for custom singletons and factories. A single style should be applicable to all configuration needs, from the middle tier to web controllers.

Ease of testing. Testing either whole applications or individual application classes in unit tests should be as easy as possible. Replacing resources or application objects with mock objects should be straightforward.

To allow for extensibility. Because Spring is itself based on interfaces, rather than classes, it is easy to extend or customize it. Many Spring components use strategy interfaces, allowing easy customization.

A Layered Application Framework

Chapter 6 introduced the Spring Framework as a lightweight container, competing with IoC containers such as PicoContainer. While the Spring lightweight container for JavaBeans is a core concept, this is just the foundation for a solution for all middleware layers.

Basic Building Blocks

pring is a full-featured application framework that can be leveraged at many levels. It consists of multi-ple sub-frameworks that are fairly independent but still integrate closely into a one-stop shop, if desired. The key areas are:

Bean factory. The Spring lightweight IoC container, capable of configuring and wiring up Java-Beans and most plain Java objects, removing the need for custom singletons and ad hoc configura-tion. Various out-of-the-box implementations include an XML-based bean factory. The lightweight IoC container and its Dependency Injection capabilities will be the main focus of this chapter.

Application context. A Spring application context extends the bean factory concept by adding support for message sources and resource loading, and providing hooks into existing environ-ments. Various out-of-the-box implementations include standalone application contexts and an XML-based web application context.

AOP framework. The Spring AOP framework provides AOP support for method interception on any class managed by a Spring lightweight container. It supports easy proxying of beans in a bean factory, seamlessly weaving in interceptors and other advice at runtime. Chapter 8 dis-cusses the Spring AOP framework in detail. The main use of the Spring AOP framework is to provide declarative enterprise services for POJOs.

Auto-proxying. Spring provides a higher level of abstraction over the AOP framework and low-level services, which offers similar ease-of-use to .NET within a J2EE context. In particular, the provision of declarative enterprise services can be driven by source-level metadata.

Transaction management. Spring provides a generic transaction management infrastructure, with pluggable

剩余内容已隐藏,支付完成后下载完整资料


Spring框架介绍

Spring框架:这是一个流行的开源应用框架,它可以解决很多问题。这里主要介绍Spring的基本概念,并详细介绍其中以“bean工厂”为核心的轻量级控制反转(IoC)容器。

Spring让开发者更轻松的实现轻量级、可扩展的J2EE架构。对于我们推荐的架构模块,让Spring提供了即时可用的实现。此外,Spring还提供了同意的应用架构方式,以及大量的中间层功能模块,能大大简化了J2EE的开发,并且比传统的开发方式更加灵活。

第一章:Spring项目的出发点

1.1解决被其它框架忽略的部分

在J2EE的各个具体领域都有很多出色的解决方案----web框架、持久化方案、远程调用工具,凡此种种。然而,将这些工具整合成一个全面的架构却困难重重,甚至成为一种负担。Spring的目标就是提供一种贯穿始终的解决方案,将各种专用框架整合成一个连贯的整体架构。Spring还涉及到其它框架没有触及到的地方。例如,很少有框架提供普遍适用的事务管理或是数据库存储对象实现;即便各个领域都有很好的选择,也没有一个框架能够帮忙把所有这些东西整合到一个应用中去。因此,我们说Spring是一个应用框架,而不是web框架、IoC框架、AOP框架或者中间层框架什么的。

1.2易于选择

一个框架应该有清楚的层次划分,允许用户使用其中的单项功能,而不是把自己的整个世界观强加给用户。Spring中的许多特性---例如JDBC抽象层或者Hibernation集成----都可以作为一个库单独使用,当然也可以作为Spring整体方案的一个部分。

1.3易于使用

正如前面说过的,仅仅J2EE本身并不易用---很多常见的问题光靠J2EE都很难解决。一个好的基础框架首先应该让容易的任务容易完成,而不需要让应用开发人员现在就为将来的复杂需求(例如分布式事务)买单。框架应该帮助开发人员合理使用J2EE的服务(例如JTA),同时又避免造成对服务的依赖,从而减少不必要的复杂性。

1.4 鼓励最佳实现

Spring力求把遵循最佳实践--例如“针对接口编程”--的成本降低到最小。另一方面,Spring又力求不强加任何架构风格,而是把选择的权利留给开发者。

1.5 非入侵性

一个好的基础设施框架应保持应用组态灵活和一致,避免自定义单身和工厂的需要。一个单一的风格应该是适用于所有配置的需要,从中间层的网络控制器。

1.6 统一配置

测试整个应用程序或单个应用程序类的单元测试应该尽可能的容易。模仿对象替换资源或应用程序的对象应该是简单的。

1.7 可扩展

由于Spring本身是基于接口的,而不是类,它是很容易扩展或定制。许多Spring组件使某种形式的Strategy模式,因此可以方便定制。

第二章:一个分层的应用框架

前面我们从轻量级容器(lightwight container)的角度介绍了Spring框架,并将其与别的IoC容器(例如PicoContainer) 作了比较。虽然为JavaBean设计的轻量级容器是Spring的核心概念,但这也只是所有中间层解决方案的基础而已。

2.1 基础构建模块

Spring是一个完整的应用框架,它可以在很懂应用层发挥作用。Spring由多个子框架组成,而且这些框架都是相对独立的。不过,只要你愿意,你就可以将它们无缝集成起来,成为一个全面的应用框架,下面讲解Spring框架的关键概念。

2.1.1 bean工厂

Spring轻量级IoC容器能够配置、装备JavaBean和大多数Java对象,使得开发者不必定制Singleton和自己的配置机制。Spring提供了多个“即拿即用”的bean工厂实现。其中包括一个基于XML的bean工厂。轻量级IoC容器和依赖注入(Dependency Injcction)将是本章节关注的内容。

2.1.2应用上下文

Spring应用程序上下文添加消息来源和资源加载支持扩展bean工厂的概念,并提供钩到现有的环境中。不同的盒子的实现包括独立的应用程序上下文和基于Web的应用程序上下文的XML。

2.1.3 AOP框架

Spring的AOP框架提供的任何类的Spring轻量级容器管理方法拦截AOP支持。可以对轻量级容器管理的任何对象进行方法拦截。在bean工厂中,可以轻松的为JavaBean提供代理,从而在运行天衣无缝地将拦截器和其他的adcice整合进来。我们将在后面详细讨论Spring的AOP框架。Spring AOP的主要用途就是为了POJO提供声明性的企业级服务。

2.1.4 自动代理

Spring提供了一个更高的抽象层次的AOP框架和低水平的服务,同时也提供了很多基础性的服务,从而在J2EE环境中提供了类似于.NET的易用性--特别是,声明的企业提供的服务可以通过源代码级的元数据驱动的。

2.1.5 事务管理

Spring提供了一个通用的交易管理基础设施,可插拔的交易策略(例如JTA和JDBC)和不同的事务划分方式。后面会详细介绍Spring事务管理的基本原理,及其强大的威力和灵活性。

2.1.6 DAO的抽象

Spring定义一组通用的数据访问异常,在创建通用的DAO接口时可以用这些异常类型抛出有意义的异常信息,,独立于底层的存储机制。后面阐述了更多的细节讨论Spring对DAO的支持,以及针对JDBC JDO,Hibernate的不同实施策略。

2.1.7 JDBC的支持

Spring提供了两个层次的抽象,使得编写基于JDBC的DAO特别简单:org.springframework.jdbc.core包提供了基于模板、回调的JDBC用法,org.springframework.jdbc.object包则把关系数据库操作建模为可服用对象。比起直接使用JDBC,用Spring 的JDBC包可以提供更大的生产力和消除常见的错误,如泄漏等。Spring JDBC抽象层集成了事务抽象和DAO的抽象。

2.1.8 集成O/R映工具

Spring提供了多种O/R映射工具的支持,如Hibernate,JDO和ibatis数据库简化资源设置,采集,和释放,并且将O/R映射与整个事务和DAO抽象集成起来。这些集成软件包允许应用程序分配自定义ThreadLocal会话和本地事务进行处理,不必考虑底层究竟采用哪种O/R映射工具。

2.1.9 web MVC框架

Spring提供了一个相当干净的Web MVC实现--同样使用了统一JavaBean配置方式。使用Spring web框架时,web控制器也可以在IoC容器中配置,从而不必为“访问业务层服务”额外编写代码。Spring还提供了通用的DispatcherServlet和“即拿急用”的控制器类。请求与控制器之间的映射方式、师徒的判断、本地化、以及其他重要服务都是可以插的,使得整个框架酷友更好的扩展性。Spring web框架设计不仅仅局限于JSP,还可以与其他的视图技术--例如Velocity--无缝的结合。

2.1.10 远程调用支持

Spring提供一种薄的抽象层用于访问远程服务,避免了在应用对象中硬编码对服务的查找。线成支持的远程调用方式包括RMI,Caucho的Hessian和Burlap Web服务的协议,和基于JAX-RPCWSDL的Web服务。

虽然Spring涉及了下至事务管理、上至web MVC的不同领域,它但它解决问题的方式却是一以贯之的。一旦你学会了基本的配置方式,你将能够应用在许多领域。资源,中间层对象,和Web组件都使用同一个bean配置机制的建立。你可以将你的整个配置在一个单一的bean定义文件或分裂,它的应用模块或层;选择是为应用程序开发人员到你。有没有需要在各种不同的格式,不同的配置文件,遍布的应用。

第三章:J2EE之上的Spring

虽然Spring的许多部分可用于任何Java环境,它主要是一个J2EE应用框架。例如,有链接到一个bean工厂的JNDI资源方便的类,如JDBC数据源和EJB和JTA,分布式事务管理一体化。在大多数情况下,应用程序对象不需要与j2ee api直接,提高可重用性和意义,不需要写冗长,难以测试,JNDI查找。

因此,Spring允许应用程序代码的无缝集成到J2EE环境不被不必要地捆绑在一起。你可以建立在J2EE服务,让您的应用程序,如果没有复杂的要求选择重量轻的解决方案。例如,你需要使用JTA事务的策略,如果你面对分布式事务的要求。为一个单一的数据库,有不依赖于一个J2EE容器替代策略。这些交易和策略之间的切换只是配置;春天的一致的抽象避免任何需要更改应用程序代码。

Spring访问EJB提供支持。这是一个重要的特征(甚至在“没有EJB的J2EE一本有关)因为动态使用代理作为客户端业务代表无代码意味着春天可以使用本地的无状态会话EJB的实现程度,而不是一个根本的建筑,选择。因此,如果你想使用EJB,您可以在一个一致的架构;然而,你不需要让你的架构的基石,EJB。今年春天功能可以使开发EJB应用程序更快,因为不需要编写自定义代码在服务中心职责范围或业务代表。测试EJB客户端代码也容易得多,因为它不仅取决于EJB的业务方法接口(这是不特定的,不是在EJB)或EJB JNDI API。

Spring也提供了实现EJB的支持,在方便的超类EJB实现类的形式,其中负载基于ejb-jar.xml部署描述符指定的环境变量的Spring轻量级容器。这是一个强大的和方便的方式实现SLSBs或MDBS是细粒度的POJO立面:最佳实践,如果你选择实现EJB应用。Spring的这些特性和EJB毫无冲突,因为它只是遵循了公认的最佳实践而已。

Spring的主要目的是使J2EE更容易使用和促进良好的编程实践。Spring不重新发明轮子,这样你会在spring找不到登录包,连接池,分布式事务协调器。这些特征是由其他的开源项目,如Jakarta Commons测井提供(Spring使用其所有的日志输出),Jakarta Commons DBCP(可作为局部数据源)和ObjectWeb JOTM(可作为事务管理器)或通过你的J2EE应用服务器。出于同样的原因,Spring不提供O/R映射层:有良好的解决问题的方法,如Hibernate,JDO。

Spring的目标是使现有的技术更容易使用。例如,虽然Spring不是低级事务协调业务,它提供了在jta或者任何交易策略的一个抽象层。Spring为Hibernate提供的中间层的基础设施也很受欢迎,因为它提供了像SessionFactory的设置,许多常见问题可以解决,ThreadLocal会议,与异常处理。与Spring HibernateTemplate类,Hibernate DAO实现方法可以减少到一个衬垫,同时适当参与交易。

Spring框架的目的并不是要取代J2EE中间层服务。这是一个应用程序框架,使访问低级J2EE容器服务更容易。此外,它提供了在某些情况下,某些J2EE服务的轻量级的替代品,如代替JTA JDBC基础交易策略时,只使用一个数据库。基本上,Spring将帮助你编写极具可伸缩性的应用程序。

第四章:web应用中的Spring

在J2EE环境中,Spring有一种典型的用法:为J2EE web应用提供逻辑中间层的基本骨架。Spring提供了“web应用上下文”的概念,将一个强大的轻量级IoC容器无缝结合到web环境中,各种web层程序--不管是Struts、webWork、JSF、Spring web MVC还是其他自制的方案--都可以使用IoC容器。

下面的代码显示了这样一个Web应

剩余内容已隐藏,支付完成后下载完整资料


资料编号:[234246],资料为PDF文档或Word文档,PDF文档可免费转换为Word

您需要先支付 30元 才能查看全部内容!立即支付

企业微信

Copyright © 2010-2022 毕业论文网 站点地图