spring framework
DESCRIPTION
A presentation given my me on Spring in Aftek.TRANSCRIPT
Spring FrameworkSpring FrameworkPresented by Preetam PalweAftek Limited
IntroductionIntroductionSpring is a open source application
framework for Java (and .NET)Replacement or addition to EJBNo “Reinventing the wheels” rather
integrating with proven frameworksConfigurable using XML (or
annotations) metadataFirst version in 2002 by Rod Johnson
(released with his book “Expert One-on-One J2EE Design and Development”)
VMware acquired SpringSource in 2009
Modules (Features)Modules (Features)Inversion of Control (IoC)
◦Managed objects◦Dependency injection
Data access◦OR mapping integration◦JDBC templates◦Transaction management
Aspect Oriented Programming (AOP)
Testing MVC (and many more…)
Inversion of Control (IoC)Inversion of Control (IoC)IoC container manages object’s
lifecycle Managed objects are called as
beans!Dependency injection via
constructors, properties, factory methods
Data accessData accessIntegration with many data access
frameworks JDBC, Hibernate, JPA etc ◦Resource management like connections
etc◦Uniform exception handling (using
exception hierarchy) ◦Transaction management
JDBC transactions OR mapping (Unit of Work) transactions JTA transactions Integration with messaging and caching
systems
Data access (cont)Data access (cont)Template classes
◦Based on Template Method pattern◦JDBC templates helps eliminate
boilerplate code in DAOs ◦JMS templates ◦Templates for OR mapper
technologies
Aspect Oriented Aspect Oriented Programming (AOP)Programming (AOP)Separation of cross-cutting concernsIncrease in modularityOwn interception based AOP
frameworkConfigured at runtime (no
compilation step needed)Same nomenclature as that of
AspectJ (aspect, advice, pointcut etc)
Integration with AspectJUsed for transaction management,
security, JMX etc
TestingTestingEasy to unit test since everything is
POJO◦IoC helps (Spring bean factories, contexts
can be setup outside the container)◦No dependency on application server
services like JNDITest framework like
org.springframework.test package ◦Reuse business layer XML configuration◦Cache container configuration like JDBC
connection or Hibernate session factories◦Test methods can have transactions
(helpful for testing DAOs)
MVCMVCSpring has its own MVC
framework similar to struts◦Strategy interfaces based design◦IoC helps easier unit testing
Integration with strutsIntegration with Flex BlazeDS
AdvantagesAdvantagesEffectively organize your middle tier objects
(with/without EJB) (no need of service locators!)Promotes programming to interfaces, rather
than classes (helps to perform mock-object testing!)
Eliminate the proliferation of Singletons Minimum or zero dependency on Spring APIsEasy to unit test (no need of deployment for
testing!)Declarative transaction management using AOP
(no need of heavy EJB container!)Build applications using POJOs!
Case study: SomeProjectCase study: SomeProjectIoC
◦IoC container manage object lifecycle and dependency injection
◦IoC managed singletonsProgramming for interfaces
◦Mock object injection of business layer classes enable unit testing of presentation tier delegate classes
◦Course grain business services exposed to client objects
Case study: SomeProject Case study: SomeProject (cont)(cont)Integration with JPA
◦JPA hides OR mapping framework like Hibernate
◦DI of PersistenceContext in beansAOP
◦Declarative transaction management for service layer objects
Ease of unit testing ◦Unit testing of business layer POJOs
using Spring TestContext framework◦No need of application deployment for
unit testing
Case study: SomeProject Case study: SomeProject (cont)(cont)Business logic portability
◦Zero dependency on Spring API◦Zero dependency on Hibernate /
TopLink API (JPA helps!)◦JTA not needed and even heavy
application server not needed (deployment in tomcat!)
ReferencesReferences http://en.wikipedia.org/wiki/Spring_Framework
http://www.springsource.org
Thank you!Thank you!