Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Spring Framework

2,874 views

Published on

A presentation given my me on Spring in Aftek.

Published in: Technology, Education

Spring Framework

  1. 1. Spring Framework Presented by Preetam Palwe Aftek Limited
  2. 2. Introduction <ul><li>Spring is a open source application framework for Java (and .NET) </li></ul><ul><li>Replacement or addition to EJB </li></ul><ul><li>No “Reinventing the wheels” rather integrating with proven frameworks </li></ul><ul><li>Configurable using XML (or annotations) metadata </li></ul><ul><li>First version in 2002 by Rod Johnson (released with his book “Expert One-on-One J2EE Design and Development”) </li></ul><ul><li>VMware acquired SpringSource in 2009 </li></ul>
  3. 3. Modules (Features) <ul><li>Inversion of Control (IoC) </li></ul><ul><ul><li>Managed objects </li></ul></ul><ul><ul><li>Dependency injection </li></ul></ul><ul><li>Data access </li></ul><ul><ul><li>OR mapping integration </li></ul></ul><ul><ul><li>JDBC templates </li></ul></ul><ul><ul><li>Transaction management </li></ul></ul><ul><li>Aspect Oriented Programming (AOP) </li></ul><ul><li>Testing </li></ul><ul><li>MVC (and many more…) </li></ul>
  4. 4. Inversion of Control (IoC) <ul><li>IoC container manages object’s lifecycle </li></ul><ul><li>Managed objects are called as beans! </li></ul><ul><li>Dependency injection via constructors, properties, factory methods </li></ul>
  5. 5. Data access <ul><li>Integration with many data access frameworks JDBC, Hibernate, JPA etc </li></ul><ul><ul><li>Resource management like connections etc </li></ul></ul><ul><ul><li>Uniform exception handling (using exception hierarchy) </li></ul></ul><ul><ul><li>Transaction management </li></ul></ul><ul><ul><ul><li>JDBC transactions </li></ul></ul></ul><ul><ul><ul><li>OR mapping (Unit of Work) transactions </li></ul></ul></ul><ul><ul><ul><li>JTA transactions </li></ul></ul></ul><ul><ul><ul><li>Integration with messaging and caching systems </li></ul></ul></ul>
  6. 6. Data access (cont) <ul><li>Template classes </li></ul><ul><ul><li>Based on Template Method pattern </li></ul></ul><ul><ul><li>JDBC templates helps eliminate boilerplate code in DAOs </li></ul></ul><ul><ul><li>JMS templates </li></ul></ul><ul><ul><li>Templates for OR mapper technologies </li></ul></ul>
  7. 7. Aspect Oriented Programming (AOP) <ul><li>Separation of cross-cutting concerns </li></ul><ul><li>Increase in modularity </li></ul><ul><li>Own interception based AOP framework </li></ul><ul><li>Configured at runtime (no compilation step needed) </li></ul><ul><li>Same nomenclature as that of AspectJ (aspect, advice, pointcut etc) </li></ul><ul><li>Integration with AspectJ </li></ul><ul><li>Used for transaction management, security, JMX etc </li></ul>
  8. 8. Testing <ul><li>Easy to unit test since everything is POJO </li></ul><ul><ul><li>IoC helps (Spring bean factories, contexts can be setup outside the container) </li></ul></ul><ul><ul><li>No dependency on application server services like JNDI </li></ul></ul><ul><li>Test framework like org.springframework.test package </li></ul><ul><ul><li>Reuse business layer XML configuration </li></ul></ul><ul><ul><li>Cache container configuration like JDBC connection or Hibernate session factories </li></ul></ul><ul><ul><li>Test methods can have transactions (helpful for testing DAOs) </li></ul></ul>
  9. 9. MVC <ul><li>Spring has its own MVC framework similar to struts </li></ul><ul><ul><li>Strategy interfaces based design </li></ul></ul><ul><ul><li>IoC helps easier unit testing </li></ul></ul><ul><li>Integration with struts </li></ul><ul><li>Integration with Flex BlazeDS </li></ul>
  10. 10. Advantages <ul><li>Effectively organize your middle tier objects (with/without EJB) (no need of service locators!) </li></ul><ul><li>Promotes programming to interfaces, rather than classes (helps to perform mock-object testing!) </li></ul><ul><li>Eliminate the proliferation of Singletons </li></ul><ul><li>Minimum or zero dependency on Spring APIs </li></ul><ul><li>Easy to unit test (no need of deployment for testing!) </li></ul><ul><li>Declarative transaction management using AOP (no need of heavy EJB container!) </li></ul><ul><li>Build applications using POJOs! </li></ul>
  11. 11. Case study: SomeProject <ul><li>IoC </li></ul><ul><ul><li>IoC container manage object lifecycle and dependency injection </li></ul></ul><ul><ul><li>IoC managed singletons </li></ul></ul><ul><li>Programming for interfaces </li></ul><ul><ul><li>Mock object injection of business layer classes enable unit testing of presentation tier delegate classes </li></ul></ul><ul><ul><li>Course grain business services exposed to client objects </li></ul></ul>
  12. 12. Case study: SomeProject (cont) <ul><li>Integration with JPA </li></ul><ul><ul><li>JPA hides OR mapping framework like Hibernate </li></ul></ul><ul><ul><li>DI of PersistenceContext in beans </li></ul></ul><ul><li>AOP </li></ul><ul><ul><li>Declarative transaction management for service layer objects </li></ul></ul><ul><li>Ease of unit testing </li></ul><ul><ul><li>Unit testing of business layer POJOs using Spring TestContext framework </li></ul></ul><ul><ul><li>No need of application deployment for unit testing </li></ul></ul>
  13. 13. Case study: SomeProject (cont) <ul><li>Business logic portability </li></ul><ul><ul><li>Zero dependency on Spring API </li></ul></ul><ul><ul><li>Zero dependency on Hibernate / TopLink API (JPA helps!) </li></ul></ul><ul><ul><li>JTA not needed and even heavy application server not needed (deployment in tomcat!) </li></ul></ul>
  14. 14. References <ul><li>http://en.wikipedia.org/wiki/Spring_Framework </li></ul><ul><li>http://www.springsource.org </li></ul>
  15. 15. <ul><li>Thank you! </li></ul>

×