International Journal of Innovative Technology and Exploring Engineering (IJITEE)
ISSN: 2278-3075, Volume-3, Issue-2, July 2013
The Spring Framework: An Open Source Java
Platform for Developing Robust Java Applications
Dashrath Mane, Ketaki Chitnis, Namrata Ojha
Abstract— The fundamental concepts of Spring Framework is presented in this paper.Spring framework is an open source Java platform that provides comprehensive infrastructure support for developing robust Java applications very easily and very rapidly.The Spring Framework is a lightweight solution and a potential one-stop-shop for building your enterprise-ready applications.
IndexTerms— Aspect Oriented Programming, Dependency Injection, IoC Container, ORM.
I. INTRODUCTION
Spring is the most popular application development framework for enterprise Java. Millions of developers around the world use Spring Framework to create high performing, easily testable, reusable code. Spring framework is an open source Java platform and it was initially written by Rod Johnson and was first released under the Apache 2.0 license in June 2003.
Spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 2MB.The core features of the Spring Framework can be used in developing any Java application, but there are extensions for building web applications on top of the Java EE platform. Spring framework targets to make J2EE development easier to use and promote good programming practice by enabling a POJO-based programming model.
The Spring Framework provides a comprehensive programming and configuration model for modern Javabased enterprise applications - on any kind of deployment platform. A key element of Spring is infrastructural support at the application level: Spring focuses on the 'plumbing' of enterprise applications so that teams can focus on application-level business logic, without unnecessary ties to specific deployment environments. Spring includes:
- Flexible dependency injection with XML annotationbased configuration styles
- Advanced support for aspect-oriented programming with proxy-based and AspectJ-based variants.
- First-class support for common open source frameworks such as Hibernate and Quartz
- A flexible web framework for building RESTful MVC applications and service endpoints
Spring is modular in design, allowing for incremental adoption of individual parts such as the core container or the JDBC support. While all Spring services are a perfect fit for the Spring core container, many services can also be used in a programmatic fashion outside of the container.
Supported deployment platforms range from standalone applications to Tomcat and Java EE servers such as WebSphere. Spring is also a first-class citizen on major cloud platforms with Java support, e.g. on Heroku, Google App Engine, Amazon Elastic Beanstalk and VMwares Cloud Foundry.[1]
II. SPRING FRAMEWORK ARCHITECTURE
Spring could potentially be a one-stop shop for all your enterprise applications; however, Spring is modular, allowing you to pick and choose which modules are applicable to you, without having to bring in the rest.The Spring Framework provides about 20 modules which can be used based on an application requirement.
Fig. 1. Spring Framework Architecture
A. Core Container
The Core Container consists of the Core, Beans, Context,and Expression Language modules whose detail is as
follows:
-
The Core module provides the fundamental parts of the framework, including the IoC and Dependency
Injection features. - The Bean module provides BeanFactory which is a sophisticated implementation of the factory pattern.
- The Context module builds on the solid base provided by the Core and Beans modules and it is a medium to access any objects defined and configured. The ApplicationContext interface is the focal point of the Context module.
- The Expression Language module provides a powerful expression language for querying and manipulating an object graph at runtime.
B. Data Access/Integration
The Data Access/Integration layer consists of the JDBC,ORM, OXM, JMS and Transaction modules whose detail is
as follows:
- The JDBC module provides a JDBC-abstraction layer that removes the need to do tedious JDBC related coding.
- The ORM module provides integration layers for popular object-relational mapping APIs, including JPA,JDO, Hibernate, and iBatis.
- The OXM module provides an abstraction layer that supports Object/XML mapping implementations for JAXB, Castor, XMLBeans, JiBX and XStream.
- The Java Messaging Service JMS module contains features for producing and consuming messages.
The Transaction module supports programmatic and declarative transaction management for classes that implement special interfaces and for all your POJOs.
C. Web
The Web layer consists of the Web, Web-Servlet, WebStruts, and Web-Portlet modules whose detail is as follows:
- The 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.
- The Web-Servlet module contains Springs model-viewcontroller (MVC) implementation for web applications.
The Web-Struts module contains the support classes for integrating a classic Struts web tier within a Spring application.
D. M
剩余内容已隐藏,支付完成后下载完整资料
国际技术创新和探索工程学报(ijitee)
国际标准刊号:2278-3075,volume-3 ISSUE-2,七月2013,
Spring框架:一个开发稳定java应用程序的开源平台
Dashrath Mane, Ketaki Chitnis, Namrata Ojha
摘要:Spring框架的基本概念将会在本文中介绍。Spring框架是一个发展强大的java开源平台,提供全面的基础设施支持。Spring框架是一个轻量级的解决方案,对于企业级应用也是一个有潜力的一站式框架。
关键词:面向切面编程,依赖注射,IOC容器,ORM。
- 引言
Spring框架是最流行的java应用程序开发企业框架。数以百万计的开发人员在世界各地使用Spring框架来创建高执行,易于测试,可重复使用的代码。Spring框架是一个开源的java平台,它一开始是约翰逊创造出来的,2003年6月在Apache 2的许可下第一次发行。
Spring是轻量级的。Spring框架的基本版本是在2MB。Spring框架的核心特征可用于开发任何java应用程序,也有对高级的java构建Web应用程序的扩展JavaEE平台。Spring框架的目标是使J2EE开发更容易使用和通过提供一个基于POJO编程模型的实践促进良好的编程。
Spring框架提供了一个全面的基于Java的企业应用现代任何部署规划和配置模型平台。Spring的一个关键因素是基础设施支持在应用层面:Spring重点的“管道”企业应用,使团队可以专注于应用层业务逻辑,无需不必要的联系具体部署环境。框架包括:
- 用XML配置方式灵活Annotation依赖注入
- 面向方面编程的高级支持与基于代理和基于面向切面的编程。
- 一类支持公共开放源码框架如Hibernate
- 一个灵活的MVC Web框架构建应用和服务端点
框架是模块化的设计,允许增量采用独立的部件,如核心容器或JDBC支持。虽然所有的Spring服务是一个完美的适合Spring的核心容器,许多服务也可以用在容器外。
支持的部署平台包括Tomcat到java EE应用服务器等。Spring也是一个一流的框架,主要支持云平台,如Heroku,谷歌的App Engine,亚马逊, VMware的云服务。
- Spring框架的体系结构
Spring是一个一站式框架,为您的所有企业应用提供支撑;Spring是模块化的,让您选择哪些模块是适用于你,而不必带来浪费。SPring框架提供了约20个可根据应用要求使用的模块。
图一. Spring框架的体系结构
- 核心容器
核心容器由核心,豆类,上下文,和表达语言模块,其细节是如下:
- 核心模块提供的基本部分框架,包括面向切面编程控制反转和依赖注射特点。
- Bean组件提供复杂的工厂模式BeanFactory。
- Context模块在由核心和beans模块提供的基础上建立,它是一种介质访问任何定义和配置的对象。ApplicationContext是Context模块的接口。
- 表达式语言模块在运行时提供了强大的用于查询和操作对象的表达式语言。
- 数据存取
数据访问层包括JDBC,ORM,OXM,JMS和事物模型,细节如下:
- JDBC模块提供了一个抽象层这就不需要做繁琐的JDBC相关编码的工作。
- ORM模块提供集成层流行的对象关系映射的API,包括JPA,JDO、Hibernate、iBATIS。
- OXM模块提供了一个抽象层支持对象/ XML映射实现JAXB,Castor,XMLBeans,JiBX和XStream。
- java消息服务JMS模块包含生产和消费信息的特点。
- 事务模块支持编程和对类的声明式事务管理实施特殊的接口和你所有的POJO。
- 网络
Web层由Web,Web Servlet,webstruts,和Web模块的详细内容如下:
- 网络模块提供基本的网络导向整合多个文件上传等功能,IOC容器的初始化用servelet listener和面向网络的应用环境。
- Web Servlet模块包含Spring的模型视图控制器(MVC)的Web应用的实现。
- Struts的Web模块包含支持类工作的一个经典的Struts Web层内的Spring的应用。
- 杂项
- AOP模块提供了面向方面编程实现允许您定义方法拦截器和干净的减耦代码实现的功能,应该分开点切。
- 切面模块提供了与AspectJ这又是一个强大的和成熟的面向方面的编程(AOP)的集成框架。
- 该仪器模块提供了类仪器支持和类装载机的实现,用于在某些应用程序服务器。
- 测试模块支持与JUnit或TestNG框架Spring组件测试。
三、Spring 控制反转容器
Spring容器是Spring框架的核心。容器将创建对象,它们连接在一起,配置,和管理他们的完整的从创建到销毁的生命周期。Spring容器使用依赖注入来管理构成应用程序的组件。
容器通过读取配置元数据提供说明什么样的对象被实例化,配置和组装。配置元数据可以代表可以通过XML、java注释,或java代码。下面的图是一个Spring IOC容器利用java POJO类和配置元数据产生完全配置和可执行的系统或应用程序的抽象视图。
图二. Spring IOC 容器
Spring提供以下2种不同类型的容器。
- Spring的BeanFactory容器
这是最简单的容器提供基本的支持。BeanFactory和相关接口,如BeanFactoryAware,initializingbean,disposablebean,大量向后兼容的目的是在Spring和第三方框架融合。
- Spring ApplicationContext的容器
该容器将增加更多企业特定功能,例如从属性文件中解析文本消息的能力,以及将应用程序发布到感兴趣事件侦听器的能力。这个容器是由
org.springframework.context.applicationcontextinterface定义。ApplicationContext容器包含所有功能的BeanFactory容器,所以一般建议在BeanFactory。BeanFactory仍然可以用于轻应用如移动设备或者程序应用的数据量和速度是重要的。
- Beans
构成您的应用程序和管理IOC容器的对象的对象被称为Beans。Bean是一个由Spring IOC容器对象,实例化,组装的对象。Beans是用来提供给容器配置元数据,例如,以XML的形式定义。
- Spring配置元数据
有以下向Spring容器提供配置元数据的三种主要方法:
- 基于XML的配置
- 基于标签的配置
- 基于java配置
四、依赖注入
Spring最有特色的技术是依赖注入的反转控制,控制反转是一个普遍的概念,它可以用许多不同的方式表示和依赖注入,只是一个控制反转的具体例子。
写一个复杂的java应用程序时,应用程序类应尽可能独立其他java类,提高重用这些类的可能性和测试他们独立于其他类做单元测试。依赖注入有助于聚合,同时保持它们的独立。确切地说是什么?让我们先看一下这两句话。在这里,依赖部分翻译成一个关联的类。例如,A类是依赖于类B现在,让我们看看第二部分,注射。所有这一切的意思是,B类将通过IOC注入到A类中。
依赖注入可以在参数传递给构造函数的方式或通过使用setter方法后发生。认为你有一个应用程序有一个文本编辑器组件,你想提供拼写检查。你的标准代码将看起来像这样:
public class TextEditor {
privateSpellCheckerspellChecker;
publicTextEditor() {
spellChecker = new SpellChecker();
}
}
我们做的是创建一个文本编辑器和拼写检查之间的相关性。在一个反转的控制方案,我们将这样做的事情:
public class TextEditor {
privateSpellCheckerspellChecker;
publicTextEditor(SpellCheckerspellChecker) {
this.spellChecker = spellChecker;
}
}
在这里,一个文本编辑器不应该担心拼写检查的实施。拼写检查程序将独立实施,将在一个文本编辑器实例化的时候提供文本编辑器和这整个过程控制Spring框架。我们从一个文本编辑器将总量控制和保持它在其他地方(ie.xml配置文件)和依赖性(即类的拼写检查器)是通过一个类的构造函数注入类文本编辑器。从而控制流“倒”的依赖注入(DI)因为你有有效的授权通过一些外部的系统。第二个方法注入依赖的是通过文本编辑器类的setter方法,我们将创建实例,该实例将拼写检查器用于调用setter方法来初始化一个文本编辑器的属性依赖注入有几个重要的优点。例如:
-
- 因为组件不需要在运行时间寻找合作,他们更容易编写和维护。在Spring的IOC里面,成分表达依赖其他组件,通过暴露JavaBean的setter方法或构造函数的参数。等效EJB将JNDI查找,要求开发商写出环境假设代码。
- 出于同样的原因,应用代码变得非常容易测试。例如,JavaBean属性简单,核心java和易于测试:简单地写一个独立的JUnit测试方法创建对象并设置相关属性。
- 一个优秀的控制反转执行强保护。如果您需要使用一个通用工厂来查找合作者,您必须将结果投给所需的类型。这不是一个大问题,但它是不雅的。IOC会在您的代码和框架表达强类型的依赖,负责类型转换。这意味着,类型不匹配将被提高错误当框架配置应用;你不必担心你的代码中的类强制转换异常。
- 依赖是明确的。例如,如果应用程序尝试加载一个类的属性文件或连接到一个数据库实例,对环境的假设可能不阅读代码是显而易见的(复杂的测试和降低部署的灵活性)。与依赖注入的方法,依赖关系是明确的,而明显的构造函数或JavaBean属性。
- 大多数业务对象不依赖于IOC的容器。这使得它易于使用传统的代码,并且易于使用的对象是IOC容器内或外部,例如,Spring用户经常配置Jakarta Commons DBCP数据源作为一个Bean:无需编写任何自定义代码来做这个。我们说,IOC容器是没有侵入性的:使用它不会入侵你的代码依赖于APIs。几乎任何POJO可以成为Spring bean工厂的一部分。与现有的JavaBeans组件或对象的构造函数multiargument 构件特别好,但Spring还提供用于实例化对象从静态工厂方法或方法对其他对象的IOC容器管理的独特的支持。
依赖注入是不同于传统的容器结构,如EJB,应用最小限度的代码对容器的依赖。这意味着你的业务对象可能有不同的运行,但是除了依赖注入框架-或在任何框架外,没有代码更改。
依赖注入是不是一个新概念,虽然它只是最近在J2EE社区被作为黄金时间。有替代的DI容器:值得注意的是,PicoContainer和HiveMind。什么是轻量级的,特别强调依赖的表达构造函数而不是JavaBean属性。它不使用元数据在java代码,这限制了它的功能。HiveMind是概念上更类似于Spring。
五、结论
Spring是一个功能强大的框架,解决了许多在J2EE开发中常见问题。Spring的特征是广泛的java环境可用,超越经典J2EE。
Spring提供了一种一致的管理业务对象的方法,并鼓励良好的做法,如编程接口,而不是类。Spring构建基础是一种基于JavaBean的属性使用控制反转。然而,这只是整体框架的一部分:Spring是独一无二的,它在一个全面复杂的问题中使用它的IOC为基础,解决所有的构建层次。
Spring提供了一个独特抽象的数据访问,包括简单和富有成效的JDBC框架,大大提高了生产率,减少了出错的可能性。春季的数据访问架构还集成了TopLink,Hibernate,JDO等O/R映射方案。
Spring还提供了一个独特的事务管理的抽象,使一系列的编程模型基于事物技术,例如JTA或JDBC。
Spring还提供了一个用标准的java的AOP框架,它提供了声明式事务管理和其他企业服务,可应用于POJO或-如果您希望实现自己的自定义方面的能力。这个框架是强大到足以使许多应用,省去复杂的EJB,EJB的同时享受与传统相关的关键服务。
引用
[1] http://www.springsource.org/tutorial
[2] http://www.tutori
剩余内容已隐藏,支付完成后下载完整资料
资料编号:[28907],资料为PDF文档或Word文档,PDF文档可免费转换为Word
课题毕业论文、开题报告、任务书、外文翻译、程序设计、图纸设计等资料可联系客服协助查找。