Introduction To The Spring Framework: by Mumbai Academics
Introduction To The Spring Framework: by Mumbai Academics
Spring Framework
By Mumbai Academics
Spring
Spring
Spring (continued)
Spring Details
Spring Details
Spring Solutions
Non-intrusive
No container requirements
Simplify application development
Remove re-occurring pattern code
Productivity friendly
Unit test friendly
Very pluggable
Usually open source
Examples:
IoC container
AOP
Spring IoC
Inversion of Control
Dependency injection
Beans define their dependencies through constructor
arguments or properties
The container provides the injection at runtime
Decouples object creators and locators from application logic
Easy to maintain and reuse
Testing is easier
Useful for separating dao and business layer
Useful for separating controllers and business layer
The code is more extensible, easier to read, and
modules/layers can easily be replaced
Singleton
Prototype
(non-singleton)
init-method
destroy-method
attributes
public void
setMinimumAmountToProcess(double d){
this. minimumAmountToProcess = d;
}
public void setOrderDAO(IOrderDAO odao){
this.orderDAO = odao;
}
}
Spring BeanFactory
Spring ApplicationContext
Configuring an XMLWebApplicationContext
<context-param>
<param-name>contextConfigLocation</paramname>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoader
Listener
</listener-class>
</listener>
Configuring an XMLWebApplicationContext
<context-param>
<param-name>contextConfigLocation</paramname>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoader
Servlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
Spring AOP
Spring
AOP
Framework
that builds on the aopalliance interfaces.
Aspects are coded with pure Java code. You do not need
to learn pointcut query languages that are available in other
AOP implementations.
Separates the core business code from the aspects we
wrap around it: security, transaction management,
monitering,logging
Spring aspects can be configured using its own IoC
container.
Spring
AOP to separate concerns, increase
Attempts
modularity, and decrease redundancy
Separation
Dont
of Concerns (SoC)
Cross-Cutting
Concerns
Supports
Spring
AOPthe following advices:
method before
method after returning
throws advice
around advice (uses AOPAlliance MethodInterceptor directly)
Without AOP
With AOP
HibernateDaoSupport
Super class for Hibernate data access objects.
Requires a SessionFactory to be set, providing a
HibernateTemplate based on it to subclasses.
JdoDaoSupport
Super class for JDO data access objects.
Requires a PersistenceManagerFactory to be set, providing a
JdoTemplate based on it to subclasses.
SqlMapDaoSupport
Supper class for iBATIS SqlMap data access object.
Requires a DataSource to be set, providing a SqlMapTemplate
doInXXX(Object)
Spring has its own exception handling hierarchy for DAO logic.
Can
Unit testing
Allows
MVC Framework
Customizable
The DispatcherServlet
The Spring Web model-view-controller (MVC) framework is
designed around a DispatcherServlet that handles all the
HTTP requests and responses. The request processing
workflow of the Spring Web MVC DispatcherServlet is
illustrated in the following diagram:
All the above mentioned components ie. HandlerMapping, Controller and ViewResolver are parts
ofWebApplicationContext which is an extension of the plain ApplicationContext with some extra features necessary for web
applications.
JavaMail helpers
Many ORM tools are supported: Hibernate, JDO, Apache OJB, iBATIS
Templates using IoC to reduce the amount of code in the DAO objects
Scheduling support via Quartz
Convenience implementation classes for
http://acegisecurity.sourceforge.net/
Very good framework!