Thursday 2 February 2012

Spring Introduction




Light weight business component Development and Integration framework
Follows Factory Pattern
Features: IoC Container, Light weight Component Development and AOP
Spring History
Spring is an open source Java & J2EE application framework developed by Rod Johnson. The framework was first released in June 2003. The major milestones are 1.0, 1.2.6, 2.5 and 3.0.This framework can be used in both in Java standalone and J2EE applications. One way we can say this is replacement to EJB and also more than an EJB. 
It has following modules:



Spring Core Module
Contains two interfaces called BeanFactory and ApplicationContext. These interfaces are having so many sub classes.  The sub classes of these interfaces are called as Spring Container Classes. These Container classes are used to create java class instances using constructor, passes required objects into it and manages lifecycle service. The additional features of InternationalizationN (I18N) support, supporting event listeners, quartz service etc are supported by ApplicationContext and its interfaces. The main difference between BeanFactory and ApplicationContext is BeanFactory lazy loads all beans. BeanFactory and its sub classes lazy loads all bean instances. The bean instances are created when we call getBean() method on BeanFactory.

Whereas in ApplicationContext all bean instances are loaded at the time of container startup itself so that in enterprise applications all bean instances are created at the time of spring container startup so that when J2EE components needs required resources they are already instantiated, dependency injected and initialized so that directly we can use them. Initialization time of dependent objects reduces in J2EE applications. ApplicationContext and its sub classes creates objects creates bean instances in a eager loaded way.
BeanFactory interface sub classes are:
·        XmlBeanFactory
o   new XmlBeanFactory(new ByteArrayResource(barray[]))
o   new XmlBeanFactory(new ClassPathResource(pathFromClasspathSetting))
o   new XmlBeanFactory(new FileSystemResource(fullPath))
o   new XmlBeanFactory(new InputStreamResource(new FileInputStream(filePath)))
o   new XmlBeanFactory(new ServletContextResource(sctxt, pathFromWEB-INF))
·        AbstractAutowireCapableBeanFactory
o   DefaultListableBeanFactory
§  XmlBeanFactory
·        StaticListableBeanFactory
ApplicationContext interface and its sub classes are:
·        ClassPathXmlApplicationContext
o   new ClassPathXmlApplicationContext(configLocationFromClasspath)
·        FileSystemXmlApplicationContext
o   new FileSystemXmlApplicationContext(fullPathOfConfigLocation)
·        GenericApplicationContext
o   GenericWebApplicationContext
o   StaticApplicationContext
·        StaticPortletApplicationContext
·        StaticWebApplicationContext
·        XmlPortletApplicationContext
·        XmlWebApplicationContext
In web mvc module DispatcherServlet reads configuration files from /WEB-INF/applicationContext.xml from the root context and /WEB-INF/disp-servlet.xml




Spring JDBC DAO Module
This module is having some convenient classes using which we can implement JDBC code in DAO classes with minimum API and also exception handling is implicitly performed. We need not have to handle exceptions during this module API.  Various types of DataSource / Connection pooling classes are provided to created DB connection objects.  JdbcTemplate and some more classes are provided to simplify using JDBC API. Some Transaction management classes are also provided to handle transaction when executing JDBC API and SQL statements.
·        JdbcTemplate
·        BatchPreparedStatementSetter
·        CallableStatementCallback
·        CallableStatementCreator
·        ConnectionCallback
·        PreparedStatementCallback
·        PreparedStatementCreator
·        ResultSetExtractor
·        RowCallbackHandler
·        RowMapper
·        StatementCallback
·        SimpleJdbcTemplate
·        NamedParameterJdbcTemplate
·        SimpleJdbcCall
·        JdbcDaoSupport
·        SingleConnectionDataSource
·        DelegatingDataSource
·        LazyConnectionDataSourceProxy
·        TransactionAwareDataSourceProxy
·        UserCredentialsDataSourceAdapter
·        JndiDataSourceLookup
·        SqlRowSet

Spring ORM DAO Module
This module contains convenient classes to use ORM frameworks like Hibernate, TopLink, JDO, iBatis, OJB, JPA. Features of this module are Lazy Loading, Eager Fetching, Caching, Cascading, Thread-safety, Light weight Template classes, Convenience support classes, Resource management etc.
·        HibernateCallback
·        HibernateTemplate
·        HibernateInterceptor
·        HibernateTransactionManager
·        LocalDataSourceConnectionProvider
o   LocalJtaDataSourceConnectionProvider
o   TransactionAwareDataSourceConnectionProvider
·        LocalSessionFactoryBean
·        LocalTransactionManagerLookup
·        JtaTransactionManager
·        AnnotationSessionFactoryBean
·        HibernateDaoSupport

Spring Web MVC Module
This module deals with implementing Spring’s own MVC framework like Struts, JSF etc. This module main classes and interfaces are DispatcherServlet, HandlerMapping, Controller and its sub classes (such as
·        AbstractController
o   BaseCommandController
§  AbstractCommandController
§  AbstractFormController
·        AbstractWizardFormController
·        SimpleFormController
o   CancellableFormController
o   AbstractUrlViewController
§  UrlFilenameViewController
o   MultiActionController
o   ParameterizableViewController
o   ServletForwardingController
o   ServletWrappingController

·        ModelAndView

·        ViewResolver
o   AbstractCachingViewResolver
§  ResourceBundleViewResolver
§  UrlBasedViewResolver
·        AbstractTemplateViewResolver
o   VelocityViewResolver
§  VelocityLayoutViewResolver
·        InternalResourceViewResolver
·        JasperReportsViewResolver
·        XsltViewResolver
§  XmlViewResolver
o   BeanNameViewResolver
o   FreeMarkerViewResolver
and various View classes such as Velocity templates, Free Marker, Designing layout with  Tiles, Generating non-HTML O/Ps such as PDF, Excel, Jasper Reports, JFreeCharts.

Spring AOP Module
After completion of developing business component with all ORM DAOs, using this module classes we can apply cross cutting concerns/middleware services to business component in a light weight, pluggable manner. This module deals with Aspects, Advices (MethodBeforeAdvice, AfterReturningAdvice, MethodInterceptor, ThrowsAdvice), Joinpoints, Pointcuts (StaticMethodMatcherPointcut, DynamicMethodMatcherPointcut), Advisors (DefaultPointcutAdvisor), Introductions, Proxies, Spring AOP container class ProxyFactoryBean.

Spring Context Module
This module deals with Accessing and exposing spring business components as RMI Services using Spring HTTP Invoker, Caucho’s Hessian Burlap protocol, Producing spring components as WebService, accessing web service, Sending Emails, Scheduling tasks, Sending messages into JMS server using with JMSTemplate, Accessing EJB, InternationalizatioN implementation, Transaction management, Security, Logging, Testing etc.