Introduction of the Spring Web Application Framework

batterycopperInternet and Web Development

Nov 12, 2013 (3 years and 7 months ago)

79 views

Introduction of the Spring Web Application Framework


Lance Berry

CIS 764 Fall 2006

Enterprise Database Design

Kansas State University



Abstract


This paper will attempt to provide a brief overview of the Spring Framework as
defined by the Open Source Sp
ring Framework project and its affiliate website
www.springframework.org
. This paper will attempt to provide a description of features,
advantages, and disadvantages of using the Spring framework.


Introduct
ion


Most web application frameworks, such as the STRUTS framework, attempt to be
a “do
-
all, be
-
all” solution to developing enterprise
-
level applications. In many ways this
can be useful, providing
simplicity

of design by using one technology and framewor
k. In
some ways, though, this can be cumbersome and difficult to incorporate. The Spring
framework ventures a different approach to the web application paradigm by providing
an “as needed” basis. As a standalone web development framework, Spring can pro
vide
many of the
necessary to components to build an enterprise application. However, the
strength and unique character of Spring is that it can integrate with other technologies and
applications seamlessly and easily.


Model


The Spring Model is divide
d into several different areas as defined by this picture:


1




Core


Uses Inversion of Control to decouple applications and classes. POJO’s
and POJI’s, as well as newly developed classes
,

are developed and referenced as
beans.
No one class is dependent

on any other classes. The Core component uses
a Dispatcher servlet to route request and responses.




AOP


Aspect Oriented Programming. Aspect Oriented Programming is an
extension of the Object Oriented Programming paradigm. AOP allows
programmers to i
nject programming calls before, after, or during execution calls
without directly modifying the resultant class. In addition to having a core AOP
stack, Spring also provides integration with the AspectJ stock.




DAO


Data Access Object. Provides basic JD
BC connectivity and transaction
management.




ORM


Object Relational Mapping. Instead of having a built
-
in component for
this particular technology, Spring relies on other open source projects. Object
Relational Mapping is the means of associating an o
bject with its container.
Traditionally, database SQL access cannot provide a hierarchical structure. Data
is received in the form of rows and columns. Spring provides hooks into several
different popular technologies including Hibernate, Toplink, JDO,
and iBATIS.




JEE


Java Enterprise
Edition
. Provides both synchronous and asynchronous e
-
mail message ca
pability, remoting capability, and EJB integration. This is
provided by hooks into other technologies such as Java Management Extensions
(JMX) which p
rovides distributed web applications, Java Messaging Service
(JMS) which provides messaging capability. The JEE component provides
connectors to standard EJB’s and connectors through the Java Connector
Architecture (JCA).




Web Tier


Provides the visual c
omponents of the enterprise application. Not
only does Spring provide its own Model
-
View
-
Controller piece, it can hook into
several different components including newer technologies such as Jasper and
Velocity, older technologies such as Struts and Webwor
k, and basic view
components such as Java Server Faces (JSF) and Java Server Pages JSP. Spring
also supports Portlets,
which are similar to servlets except that they have two
distinct phases, action and render. The ‘Action’ phase occurs only once, wherea
s
the ‘Render’ phase may occur several times to produce various views.










Advantages of Using Spring

Spring has numerous advantages. One of the biggest advantages (and the one
most referenced) is its inherent modularity. Outside of the Inversion of

Control
container, being the BeanFactory, virtually any piece of Spring can use a different
technology. Spring can use this modularity to incorporate legacy applications that are
built as Enterprise Java Beans (EJB’s) or as Plain Old Java Objects (POJO’s
) and Plain
Old Java Interfaces (POJI). Using virtually any other framework requires rebuilding the
application to conform to its model.
Another big advantage to using Spring, is the ability
to unit test each component. Spring primarily uses Aspect Orie
nted Programming (AOP)
to support this. Most of the other frameworks can only test the integration of the entire
application. This makes testing cumbersome and difficult.


Disadvantages of Using Spring

The modularity of Spring comes at a surprising cos
t. While other frameworks
such as Struts rely on one XML file for configuration, Spring uses several different XML
files which are incorporated as metadata within the application. For smaller applications,
this is not as obvious. With larger application
s, this presents a unique difficulty. In this
way, Spring is termed as “too loose”
2
. Another disadvantage is that Spring also relies
heavily on its integration with other technologies. In some cases, such as the Spring
MVC and the AOP stack, limited fu
nctionality is provided. However, if extensive
functionality is required, Spring must hook into the other technologies. In the case of the
JEE and ORM components, Spring does not even provide a basic functionality. This is
onl
y important if these are ne
eded. If they are needed, it requires knowledge in these
other areas in addition to Spring itself. Configuring the other components in is an easy
matter. Using them effectively is a different matter.


How Spring Works

Spring manages the application with

a single IOC container, which references
other objects as “beans”. The objects do not rely on each other for dependency, but
instead defer to the Spring container. In this way, Spring is able to incorporate POJO’s
and POJI’s as beans simply by referenci
ng them.


3





This is an example configuration of a Bean Factor
y
:


Resource resource=new FileSystemResource(“beans.xml”);

BeanFactory factory=new XmlBeanFactory(resource);


which references a bean configuration data file:


<?xml version=”1.0…..



<bean
id=”…” class=”…”/>


Or possibly multiple configuration files:



<beans>


<import resource=”services.xml”/>


<import resource=”resources/messageSource.xml”/>


<bean id=”bean1” class=”…”/>


<bean id=”bean2” class=”…”/>


Incorporating Other Technologies

To in
corporate other technologies, Spring treats them as other beans. For
example, to reference a Hibernate object:


<beans>



<bean id="myDataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy
-
method="close">


<property name="driverClassName"

value="org.hsqldb.jdbcDriver"/>


<property name="url"
value="jdbc:hsqldb:hsql://localhost:9001"/>


<property name="username" value="sa"/>


<property name="password" value=""/>


</bean>



<bean id="mySessionFactory"
class="org.springframework.or
m.hibernate3.LocalSessionF
actoryBean">


<property name="dataSource" ref="myDataSource"/>


<property name="mappingResources">


<list>


<value>product.hbm.xml</value>


</list>


</property>


<property name="hibernateProperties">



<value>


hibernate.dialect=org.hibernate.dialect.HSQLDialect


</value>


</property>


</bean>

<
/beans>

4


Conclusion

Spring is enjoying the usual buzz that surrounds any new technology. While I
agree that it seems to support a modular
approach, I do not feel it meets the expectations
of simplicity that it touts itself to be.
It seems that the two determining factor of using
Spring is whether other components are really necessary and whether unit testing is
required. Until more example
s and better documentation are created, using Spring will
be a matter of choice instead of a de facto standard.































FOOTNOTES


1.

Johnson, Rod “Spring Framework Reference Documentation” Overview
Section 1.1

2.

Lee, Bob “I Don’t Get
Spring”

3.

Johnson, Rod “Spring Framework Reference Documentation” IOC Container
Section 3

4.

Johnson, Rod “Spring Framework Reference Documentation” Hibernate
Section 12.2


References




Raible, Matt “Comparing Web Frameworks”.
https://equinox.dev.java.net/framework
-
comparison/WebFrameworks.pdf
.
2006



Harrop and Machacek
,
Pro Spring

Apress Publishing. 2005



Johnson, et al. “Spring Framework Reference Documentation”.
http://static.springframework.org/spring/docs/2.0.x/refe
rence/index.ht
ml
.
2006