Spring Framework Tutorial

 

            To know about the Spring Framework we need to know about the Spring first. let's find out what Spring is.

            Spring is an open source framework, created to address the complexity of enterprise application development. Java application can benefit from Spring in terms of simplicity, testability, and loose coupling.

            Spring is lightweight dependency injection and aspect-oriented  container and framework. To know more what is lightweight,  dependency injection and aspect-oriented, see the description given below.

  • Lightweight - Spring is lightweight in terms of size and  overhead. Bulk of the Spring Framework is distributed in a single JAR file that weighs just over    2.5 MB. And the processing overhead required by the Spring is negligible.
  • Dependency injection (DI)- It is a form of Inversion Of Control(IOC). We can achieve loose coupling through this DI. DI is basically container gives  an object what  it needs(dependencies) at instantiation without waiting to be asked, instead of an object looking up dependencies from a container.
  • Aspect-oriented - In Spring that enables cohesive development by separating application business logic from system services like logging transaction support. Here Application objects perform business logic and nothing more.
  • Container - Spring is a container in the sense that it contains and manages the life cycle and configuration of application objects.
  • Framework - Spring makes it possible to configure and compose complex applications from simpler components.

 

Spring  Framework:

            Spring framework is made up of several well defined modules that are built on top of the core container. We can build whole Enterprise applications using all Spring Framework modules. But if we don't want to build our application fully on Spring Framework we are free to choose the modules that suit our application and look to other options when Spring does not suit.

            Below figure shows the  Spring Framework modules.

 

            Let's take a look at each of the Spring's modules in the above fig.

 

 

Spring Core Container: 

Spring's core container provides fundamental functionality of the Spring Framework. This module contains the BeanFactory, which is the fundamental Spring container and basis on which Spring's DI is based.

 

Application context module:

It is build on top of the core container. The core module's "BeanFactory" makes Spring a container, but the context module is what  makes it a framework. This module extends the concept of BeanFactory, adding support for internationalization (I18N)messages, application life cycle events, and validation. This module provides many enterprise services such as email, JNDI access, EJB integration , remoting and scheduling, also provides support for integration with templating framework such as Velocity and FreeMarker.

 

Spring's AOP module:

Spring's AOP provides rich support for aspect-oriented programming. Aspects help to modularize cross cutting concerns. Cross cutting concerns (aspects) can be described as any functionality that affects multiple points of an application. For example security, transaction management. In OO technique for reusing common functionality is to apply inheritance and delegation. But inheritance lead to brittle object hierarchy if the same base class is used throughout an application and delegation can be cumbersome because complicated calls to the delegate object may be required. Aspects  offer a alternative to the inheritance and delegation. With AOP we can define common functionality in one place, we can declaratively define how and where this functionality is applied without having to modify the class to which we are applying the new feature. Aspects are described in terms of advice, pointcuts and joincuts.

            Spring's AOP module offers several approaches to building aspects, including building aspects based on AOP Alliance interfaces and support for AspectJ. Spring's AOP supports loose coupling of application objects.

 

Spring's JDBC abstraction and DAO module:

Using this module we can abstracts away the boilerplate code so that we can keep up the database code clean and simple, and prevent problems that result from a failure to close database resources. A new layer of meaningful exceptions on top of the error messages given by several database servers is bought in this module. In addition, this module uses Spring’s AOP module to provide transaction management services for objects in a Spring application.

 

Spring's ORM module.:

Spring also supports for using of an object/relational mapping (ORM) tool over straight JDBC by providing the ORM module. Spring provide support to tie into several popular ORM frameworks, including Hibernate, JDO, and iBATIS SQL Maps. Spring’s transaction management supports each of these ORM frameworks as well as JDBC.

 

Spring's Java Management Extensions(JMX):

Springs JMX module makes it easy to expose our application's beans as JMX MBeans. This makes it possible to monitor and reconfigure a running application.

 

Spring's Java EE Connector API(JCA):

JCA is  a more general purpose API connecting to legacy systems. JCA provides a standard way of integrating Java applications with a variety of enterprise information systems, including mainframes and databases. Spring's JCA module abstracting away JCA's boilerplate code into templates.

 

Spring's MVC Framework:

Model/View/Controller paradigm is commonly accepted  approach to building web applications such that the presentation layer is separate from the application business logic. Spring framework  integrates with several other popular MVC frameworks such as Struts. Spring  MVC framework promotes Spring's loosely coupled technique in web layer of application. A single Front Controller servlet "DispatcherServlet" that

dispatches requests to individual Controllers. Controller is a Spring Component that process the request. Handler Mapping interface used by DispatcherServlet for mapping incoming requests to individual Controllers. Request is processed by chosen controller. Controller will package up the model data and the name of view into a ModelAndView object. This ModelAndView object and request is send back to the DispatcherServlet. DispatchServlet asks a view resolver to help find the actual JSP.

 

Spring's Portlet MVC:

Web applications are page based means each request to the application. results in a completely a new page. Each page contains  the certain information. In portlet-based applications aggregate the several bits of functionality on a single web page. This provides a view into  several applications at once. Spring's Portlet MVC build on  SPring's MVC to provide a set of controller that support the Java's portlet API.

 

Spring Web Module:

Spring MVC and Spring Portlet MVC require special consideration when loading Spring application context. Spring's web module provides special support classes for Spring MVC and Spring Portlet MVC. Spring web module also provides support for several web related tasks such as multipart file upload and programmatic binding of request parameters to your business objects. It contains integration supports with Struts and JSF.

 

Spring's Remoting:

It is necessary for an application to get the functionality of another application to get its work done. To access the other application over network , some form of remoting is used for communication. Spring's remoting support enables we to expose the functionality of our Java objects as remote objects. And  it we need to access objects remotely, remoting module also makes simple work of wiring remote objects into our application as if they were local POJOs(Plain Old  Java Object)

 

Java Messaging Service:

Spring's Java Message Service (JMS) module  helps you send messages to JMS message queries and topics. This module also helps you create message-driven POJOs that are capable of consuming asynchronous messages




Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)