You are on page 1of 8

International Journal of Emerging Technology and Advanced Engineering

Website: www.ijetae.com (ISSN 2250-2459, Volume 2, Issue 6, June 2012)

Integration of Struts, Spring and Hibernate for an University Management System


Ankur Bawiskar1, Prashant Sawant2, Vinayak Kankate3, Dr. B.B.Meshram4
4

Department of Computer Technology, Veermata Jijabai Technological Institute,Matunga, Mumbai, India Head of Department of Computer Technology, Veermata Jijabai Technological Institute, Matunga, Mumbai, India

1,2,3

Abstract - This paper presents the concept of the Spring framework which is widely used in making enterprise wide applications along with other frameworks. Spring framework insists that ordinary java beans can be used with slight modifications to them. This framework is used within J2EE architecture to make it easier to develop large scale java applications. This paper presents the architecture overview of spring framework along with the features of the framework that have made the framework useful for using it along with struts and hibernate. The integration of various frameworks for an E-commerce system such as university system has also been discussed in the paper. The Spring MVC framework as an important part is also discussed along with struts mvc. This paper has a proposed architecture for a website based system using the integration of Spring, Hibernate and Struts framework. Keywords - AOP, Dispatcher, E-commerce, Hibernate, Integration, IoC, JavaEE, Mapping file, MVC, Spring, Struts

Fig 1 Architecture of Spring Framework

The architecture of spring consists of seven modules which can be shown as follows [2]: The core container Spring context Spring AOP Spring DAO Spring ORM Spring Web Module Spring MVC framework b. Features of Spring framework Spring is a free and open source framework that offers a lot of functions to developers and programmers. It was created by Rod Johnson and Juergen Hoeller jointly. The most important features of it are the Inversion of Control, Aspect oriented programming and Spring MVC. Spring has its own MVC framework that can be used with other frameworks or can be used alone. The Aspect oriented programming, IoC and MVC are the important features that facilitates the development of an enterprise applications. Aspect oriented Programming: Taking the help of AOP the various concerns present in a system can be easily separated out. Aspects can be transaction, logging and security. In Spring aspects are bundled together with the help of spring configuration file which is a xml file and coding is well modularized. [10] Example: consider the example of hotel booking system.

I.

INTRODUCTION

In todays world, with the introduction of information technology and communication media many of the companies use frameworks for making the development of their applications easier. The business today demands web applications to advertise its company so it is very important to take care of the architecture used in development of the application. Framework can be considered as a set of functions helping the developers in creating the applications. The Spring Framework is an application type framework that helps to customize java applications effectively. Even though JavaEE is widely used, it has some limitations such as reusability of code is very less, heavy development burden present [1], [5]. Spring framework when used with JavaEE makes the development easier. Spring is a layered architecture so whenever an Ecommerce system is developed using spring it has clear separation of the layers. Because of its layered architecture it allows users to select about which of its components users can use. II. a. RELATED W ORK

Architecture of Spring framework

203

International Journal of Emerging Technology and Advanced Engineering


Website: www.ijetae.com (ISSN 2250-2459, Volume 2, Issue 6, June 2012) The various types of services such as guest service, room service and staff service need the functionality provided by Logging, Security, and Transaction modules. The normal system for this would be as follows [6]: DispatcherServlet- It receives the request transferred to it by web.xml file. Controller- It handles the request and is created by user. They are objects that can respond to the actions a user takes like form filling or clicking a link. View- It can be thought of as a way of representing the output to the end users. ModelAndView- Whenever a request come its the job of ModelAndView to associate the view to the particular request. It is created by controller and when it executes it returns data and name of view. ViewResolver- It tries to resolve the view based on the output given by ModelAndView object and select the output media. There can be various output media present for the particular system or application. HandlerMapping-Whenever DispatcherServlet receives incoming requests it associates the request to individual controllers with the help of this component. The MVC model of Spring can be shown as below [6]:

Fig 2 Normal System without AOP

The same system with the help of AOP feature of spring can be drawn as follows: All the three functionalities are provided to all the three services which can be showed as below: [6]

Fig 4 Handling of request using Spring MVC Fig 3 Approach using AOP

d.

Inversion of Control: In the IoC instead application calling the framework, it is the framework that calls the components specified by an application. The dependencies are injected dynamically at run time by the container of Spring. c. Spring MVC model The Spring Framework has its own MVC model. The major components of Spring MVC are as follows [3]:

Struts MVC framework The application has central controller- a heart of framework struts (ActionServlet), which mediates between all requests and separate them to individual objects. Those objects are the bridge between the application model and assigned to it request. The model presents the application state. If the state is changed, control will be forwarded to the given view. This, to what view the control will be forwarded, is the most frequently specified in the mapping file. [31]

204

International Journal of Emerging Technology and Advanced Engineering


Website: www.ijetae.com (ISSN 2250-2459, Volume 2, Issue 6, June 2012) The above xml file specify that the property name is for hibernate framework and two property keys can be defined and are necessary for a web application they are hibernate.dialect and hibernate.show_sql. It also specifies the connection pool size. Hibernate also provide two level cache strategy that will help in retrieving the information from database in less time. Hibernate can save common data that is being frequently being retrieved by using the caching technology. When client request for a data the cache is visited first, if the data can be found from the cache it is directly sent to the user otherwise the request is sent to database again thereby increasing the speed of request and response. f. Hibernate Mapping file The Hibernate layer is called as persistence layer. Database records are mapped into Java objects based on XML definitions stored in Hibernates configuration files. An example mapping file can be shown as below: [32] <hibernate-mapping> <class name="Database.Link" table="link"> <id name="Id" type="int"> <column name="id"/> <generator class="native" /> </id> <property name="Link" type="string"> <column name="link"/> </property> <property name="Name" type="string"> <column name="name"/> </property> <many-to-one name="Account class="Database.Account" column="accid"/> </class> </hibernate-mapping> g. E-Commerce System Using Spring, Struts and Hibernate framework Spring framework can be widely used with many other web development frameworks for making of an Ecommerce application such as struts and hibernate both of them being as an open source framework. Struts framework: This framework divides web system into three layers: Model, View and Controller. Model consists of JavaBeans, EJB; View consists of JSP files; Controller is carried out by Actions [4].

Fig 5 MVC components in application based on Struts framework

Control flow between components: [31] 1. Request is called by client, which chose some action in a given interface, displayed on the screen. 2. This request is received by ActionServlet (the application controller), which after checking in the mapping file transmits it to the proper Action class. 3. Action class does specific operations in the model. 4. After the task for the model is completed Action class returns control to ActionServlet controller. Data is returned by Action contain forward key. 5. On the basis of the mentioned key and a mapping file ActionServlet calls the appropriate view, which displays a requests result. e. Integration of Spring and Hibernate Spring can be easily integrated with the ORM tool such as Hibernate with the help of xml file. The xml for the mapping can be described as below: <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql} </prop> <prop key="hibernate.connection.pool_size">${hibernate.connect ion.pool_size} </prop> </props> </property>

205

International Journal of Emerging Technology and Advanced Engineering


Website: www.ijetae.com (ISSN 2250-2459, Volume 2, Issue 6, June 2012) The architecture of struts can be shown as below [2]: For each of the above databases Hibernate will have to configure itself with the specific database. It is generally done through xml files. Consider an Oracle database being used with Hibernate then the configuration file will be oracleconfig.cfg.xml. Similarly if the database is Derby then the xml file used will be derbiconfig.cfg.xml. Hibernate has two level caches. A Hibernate Session is itself a transaction-level cache (first level cache) of persistent data being stored in database. Secondary level cache helps in preventing frequent database requests. We can add secondary cache in hibernate.cfg.xml file as below: <property name="cache.use_second_level_cache">true</property> The architecture based on integration of above frameworks can be shown as below [1]:

Fig 6 Implementation of Struts

Hibernate framework: This persistence framework reduces the complexity, difficulty while manipulating the JDBC and SQL data. It maps Java classes to database tables efficiently. It is mainly associated with databases [3], [4]. The Structure of Hibernate can be shown as below [2]:

Fig 7 Structure of Hibernate

Integration of Struts, Spring and Hibernate Struts, Spring and Hibernate frameworks can be combined easily to make an efficient and complex Ecommerce applications such as web sites. The struts framework has an efficient MVC that can help in developing the presentation tier of the website. The Spring framework can provide help in handling the business logic of the website. The Hibernate framework can used in handling the website data present in the system and help in storing and retrieving the data to and from database of any kind respectively. It works effectively with DB2, MySQL, PostgreSQl, Oracle 11g.

Fig 8 Architecture based on Spring, Struts and Hibernate framework

A. Web presentation layer The web presentation layer can be easily handled by the struts web framework. It has the responsibility for handling user requests and forwarding the responses back to client/users. It provides users with the views such as Jsp, HTML documents. [34]

206

International Journal of Emerging Technology and Advanced Engineering


Website: www.ijetae.com (ISSN 2250-2459, Volume 2, Issue 6, June 2012)

The above explains the struts configuration file and the action mapping associated with it. B. Business Logic Layer The business logic layer is taken care by the spring framework. The main features of this framework are the IoC and AOP which are used for handling the business logic. It is also used in handling the interaction with the database layer i.e. Hibernate persistence layer with the help of its Spring DAO component. [34]

The above hibernate configuration file explains the connection name, the username and password used to connect the database the mapping resource. There can be different types of hibernate configuration files based on the type of database being used such as MySQL, Oracle 11g, DB2. III. P ROPOSED SYSTEM

The above xml file explains that the bean id is transaction manager and property specified is sessionFactory. C. Data Persistence layer The data persistence layer can be easily handled using the hibernate framework. This framework makes data connectivity easier by removing the tedious JDBC connection error handling mechanisms. This layer is being called as business logic layer. This layer handles interaction with the database (DBMS) to retrieve and store data related to website. The Hibernate executes the object mapping by XML document. [34]

The Spring framework described above which has a multitier architecture can be effectively used with many other frameworks such as Struts which can be used for web presentation layer and can be easily integrated with Hibernate persistence framework which is a powerful database connectivity layer. Although spring has its own MVC layer it can easily interoperate with the presentation tier of Struts i.e. Struts mvc. The proposed system here can be considered here with the help of a website such as that of a University management system wherein students can enroll for a course and can also avail the e-learning facility provided by the university. Students can also download papers, research papers. It can generally have three layers i.e. presentation layer, business layer and database layer.

207

International Journal of Emerging Technology and Advanced Engineering


Website: www.ijetae.com (ISSN 2250-2459, Volume 2, Issue 6, June 2012) a) Presentation/View layer: The Presentation Tier or User Interface is the part the student sees when he/she opens a web page in his/her browser. It is the part that is presented to the student on the client side within their web browser. It has the responsibility for handling requests and forwarding the response back to client/students. It provides with the views that can be provided to the students such as Jsp, HTML documents. The presentation layer can be done using either spring mvc or struts. The students with the help of browser can access the research papers, download them can also browse the previous year question papers. The students can also watch the lecture videos by just registering. b) Business layer: The business layer is also called as business Logic. Business Rules are kept in a separate layer called as Spring framework layer. Typically we have to define classes, functions, procedures, properties in this layer. The business layer is generally handled efficiently using the spring framework because it has various features such as Aspect Oriented Programming and dependency injection as its core features. c) Data Access layer: The data access layer is generally used for the connectivity purpose with the database. It is used to handle the creation of databases. It handles the mapping part between the business layer and the database layer. Here generally various ORM tools can be used but for the above case study we have used Hibernate. Other ORM tools include iBATIS, JPA. Hibernate supports various databases like MySQL, Oracle 11g, Sybase, PostgreSQL, etc. The configuration file has to be modified based on type of database being used. It makes use of hibernate.cfg.xml file for its configuration. The general architecture as a three tier for any web based application can be as follows:

Fig 10 Proposed System

The above architecture can be explained as follows in terms of model, view and controller and databases as follows: a) View- Presentation Layer The view means how data/result is being presented to the students either in the form of table, charts, graphs etc. This layer is being handled by the struts framework. It provides various views such as JSP, HTML. The university system can be efficiently developed by using the struts framework as web presentation layer. Benefits of Struts MVC are as follows1. Configuration is centralized- The mapping that has to be done is present in the XML configuration file. This allows loose coupling so changes can be made and effect of the changes can be found by just editing a single xml file. 2. Form Validation- Struts provide strong validation of the form which can be applied to the registration form of the students who wish to enroll for a course. This feature is present by default in the struts framework. The main functions of the presentation/view layer are as follows1) Whenever students register by filling a form it has to do form validation, collect the form data and display result required by the students using various views either in graphical manner or pie chart, bar graphs.

Fig 9 General 3-Tier architecture

The proposed architecture for the university case study consisting of the three layers is as follows:

2) It is responsible for forwarding the request to the business layer (spring framework) and also collects responses from the business layer which does business processing and displays it to the students.

208

International Journal of Emerging Technology and Advanced Engineering


Website: www.ijetae.com (ISSN 2250-2459, Volume 2, Issue 6, June 2012) b) Controller- Business Layer The controller called as business layer is responsible for handling the business logic and perform various operations such as transaction management. In this layer we have to define classes and define procedures that have to be written in java. The university system can be managed with the help of Spring AOP and IoC both of them being the core features of Spring framework. The Spring framework is a effective contender for the middle tier (layer) because of its Aspect Oriented Programming and Inversion Of Control features. The main task of Spring framework while making it use for developing a university system are as follows: 1) The Spring framework provides Inversion of Control and Aspect Oriented Programming to handle the business objects, Aspect oriented programming makes it easier to develop the applications as compared to Object oriented programming. This business layer should be able to access and retrieve the data from data access layer being managed by the Hibernate framework. c) Model data- Data access Layer The university website can contain data to be displayed to the students which can be stored in a relational database. The student gives various details such as video lecture dated, previous year papers, etc. In order to access the database the Hibernate framework is used. There are some other ORM tools such as iBATIS which are similar to Hibernate. Hibernate supports various databases such as MySQL, Oracle 11g, PostgreSQL, Sybase, DB2. The only change has to be done in the configuration file based on the type of database being used ORM tool performs mapping from Object to relational tables. Hibernate is one such ORM tool. The spring framework with the help of its DAO module can easily connect to any ORM tool. Here Hibernate is used as an ORM tool. The mapping between Spring and Hibernate is specified in a xml file which has the two properties as hibernate.dailect and hibernate.show_sql. IV. ARCHITECTURAL B ENEFITS OF SPRING Spring Framework can be effectively used with other frameworks such as struts, hibernate. Spring provides easy access to database by using hibernate framework and avoiding the handling of error mechanism. Applications developed using this framework depends on few APIs. Due to its Inversion of Control feature the amount of time needed for testing the code is less. Because Spring is a layered architecture users can select which of its components can be used. The Spring Web MVC framework is robust, flexible and well designed for rapidly developing web applications. Spring Web MVC provides controllers so that handling of many requests from user interface becomes easier. Spring Framework can work effectively with J2EE for developing applications in an effective manner. V. CONCLUSIONS

Spring framework is a powerful framework for building enterprise wide java applications. It can also be easily integrated with some other frameworks such as struts and hibernate frameworks for developing efficient enterprise wide java applications thereby reducing the coupling and clear separation of layers so easy to understand. Due to the lightweight feature of Spring framework it is easy to use. It can easily work with a simple web server such as Tomcat that can also be used during integration of spring with other frameworks. Considering the current scenario wherein there is struts2 framework that can be used only for web tier; spring framework that provides all layers can be used effectively for all the three tiers to build an efficient enterprise application. The Spring framework can be easily integrated with any other ORM tool such as Hibernate with the help of XML mapping and also with iBATIS. With the help of combination of Spring, Struts and Hibernate we can develop powerful enterprise wide java applications. Hibernate also provides caching technology for fast retrieval of data from databases thus improving the performance of the system.

There are many architectural benefits of Spring framework when integrated with other frameworks. They can be described as follows [3]:

209

International Journal of Emerging Technology and Advanced Engineering


Website: www.ijetae.com (ISSN 2250-2459, Volume 2, Issue 6, June 2012) REFERENCES
[1] Chunsheng Zhao, Mai Jiang, Zhiyong He, The Design of ECommerce System Architecture Based on Struts2, Spring and Hibernate, IEEE Transaction Paper Dated 2010. Jiya Jiang , Tong Liu , Yu Liu,The Construction of E-Business Portal Based on Struts, Spring and Hibernate, IEEE Transaction Paper Dated 2009. Praveen Gupta, Prof. M.C. Govil, Spring Web MVC Framework for rapid open source J2EE application development: a case study, International Journal of Engineering Science and Technology, Vol. 2(6), 2010, 1684-1689 Praveen Gupta, Prof. M.C. Govil, MVC Design Pattern for the multi framework distributed applications using XML, spring and struts framework , International Journal on Computer Science and Engineering, Vol. 02, No. 04, 2010, 1047-1051 Rod Johnsonet, Professional Java Development with the Spring Framework, Publications John Wiley & Sons 2005 Craig Walls with Ryan Breidenbach, Spring in Action , Publications Manning 2008 Introduction to the Spring framework accessed from: http://www.ibm.com/developerworks/web/library/wa-Spring1/ Model-View-controller Accessed from: http://en.wikipedia.org/wiki/Model-view-controller Hao, Xiafei, Tang, Hongxi. Struts+Spring+Hibernate Integrated Framework and its Use in Log Accounting and analyzing System, International Conference Dated 2010. Ke Ju, Jiang Bo, Applying IoC and AOP to the Architecture of Reflective Middleware, International Conference Dated 2007. Research of Structure Integration based on Struts and Hibernate, IEEE Conference 2010. Erxiang Chen Personnel department Research and Design on Library Management System Based on Struts and Hibernate Framework, IEEE Conference 2009. Hui Li, Jingjun Zhang, Lei Wang, The Research and Application of Web-Based System with Aspect-Oriented Features, IEEE International Conference Dated 2010. Dipankar Majumdar, Migration from Procedural Programming to Aspect Oriented Paradigm, IEEE International Conference Dated 2009. Hui Li , GuiJun Xu , Mingji Zhou, Lingling Si, Aspect-oriented Programming for MVC Framework , IEEE Paper Dated 2010. Robert J. Walker, Elisa L.A. Baniassad and Gail C. Murphy, An Initial Assessment of Aspect-oriented Programming, ACM Paper Dated 2009. Richard Millham, Evans Dogbe, Aspect-oriented security and exception handling within an object oriented system, IEEE Paper Dated 2011. [18] Hui Li, Mingji Zhou, GuiJun Xu, Lingling Si, Aspect-oriented Programming for MVC Framework, IEEE Transaction Paper Dated 2010. [19] Struts vs spring mvc accessed from: http://www.coderanch.com/t/456799/Spring/struts-Vs-spring-mvc [20] Benefits of spring mvc over struts accessed from: http://orangeslate.com/2006/11/10/12-benefits-of-spring-mvc-overstruts/ [21] ShenJiang, YuHongzhi, HeXiangzhen, Modern Distance Education System Design Based on struts2, International Conference on Advanced Computer Theory and Engineering, Dated 2010. [22] J.Wojciechowski, B.Sakowicz, K.Dura, A. Napieralski, MVC Model, Struts Framework and File upload Issues in Web Applications Based on J2EE Platform, TCSET, Dated 2004. [23] Nana Qi, Zhimin Yang, Research of Struts2 Framework and Web Application Based on Ajax, IEEE Transaction Paper Dated 2009. [24] Yang guigui, Cheng gengguo, Bao kaomin, Wu li, Design and Realization of Equipments Archives Management System Based on Struts2 and Hibernate, IEEE Transaction Paper Dated 2010. [25] KeYin, Kaifeng,Application Research on a Persistent Technique Based on Hibernate, IEEE Conference Dated 2009. [26] Wu Peng, Exploration of a Realization Pattern of System Based on Hibernate, International Conference Dated 2010. [27] PengWu, Kaifeng, Application Research on a Persistent Technique Based on Hibernate, IEEE Conference Dated 2010. [28] Chuanlong Xia, Efficient implement of ORM use in J2EE framework: Hibernate, IEEE Conference Dated 2008. [29] PengWu Computer Center Henan University Kaifeng, China, Application Research on a Persistent Technique Based on Hibernate, IEEE Conference Dared 2010. [30] Piotr Ziemniak, Bartosz Sakowicz, Andrzej Napieralski, Object Oriented Application Cooperation Methods with Relational Database (ORM) based on J2EE Technology. [31] C. Mysiak, W. Zabierowski, A. Napieralski, Universal E-commerce Platform: Use of Web Technologies Conference Paper of CADSM Dated Feb 2007. [32] Marcin liwiski, Bartosz Sakowicz, Bartomiej wiercz, Andrzej Napieralski, Implementation of a Web Hosting Service Based on J2EE Technology TCSET Conference Paper Dated 2008. [33] HaiLanPanl, AnBao Wang2, WenRong Jiang3, Discussion of Course of E-commerce Website Construction based on Java EE Lightweight framework IEEE Conference Paper Dated 2010. [34] Pan Yuqing, Wang Jiuli, Design And Implementation of Accounting E-Business Platform for Source Documents IEEE Conference Paper Dated 2010. [35] Hibernate Cache technology accessed from: http://expertdevelopers.blogspot.in/2010/10/hibernate-secondarycache.html

[2]

[3]

[4]

[5] [6] [7] [8] [9]

[10] [11] [12]

[13]

[14]

[15] [16]

[17]

210

You might also like