Successfully reported this slideshow.
The Spring Framework Training<br />Get to know Spring Framework<br />Rohit Prabhakar<br />http://rohitprabhakar.com<br />
Get to know Spring Framework<br />The Spring Framework: Overview<br />Topics:<br /><ul><li>What is Spring?
Spring modules
Why use Spring
Dependency injection / IOC in detail
Lab Work</li></li></ul><li>Get to know Spring Framework<br />What is Spring?<br />The Spring Framework is an open source a...
Get to know Spring Framework<br />How does the Spring Framework looks like?<br />
Get to know Spring Framework<br />How does the Spring Framework looks like?<br />Each of the modules (or components) that ...
Get to know Spring Framework<br />How does the Spring Framework looks like?<br />Spring DAO:The Spring JDBC DAO abstractio...
Get to know Spring Framework<br />What does Spring Framework Offers: Summary<br />Inversion of Control container: configur...
Get to know Spring Framework<br />Why use Spring?<br />Have you ever encountered these question?<br /><ul><li>Cant’ I have...
How can I handle my every changing requirements?
How can be the architecture flexible?
Can’t I have everything in components which can be verified independently?
Can I make a plug and play software?
How can the software components reusable and changeable?
Should we use EJB? As it makes the product complex, unpredictable and un-maintainable, non-portable and everything  is fra...
…………….. And many more like these</li></ul>SPRING IS THE ANSWER!<br />
Get to know Spring Framework<br />Spring Framework’s Mission Statement<br />We believe that:<br /><ul><li>J2EE should be e...
Upcoming SlideShare
Loading in …5
×

Spring Framework Rohit

5,259 views

Published on

Published in: Technology, Education
  • Be the first to comment

Spring Framework Rohit

  1. 1. The Spring Framework Training<br />Get to know Spring Framework<br />Rohit Prabhakar<br />http://rohitprabhakar.com<br />
  2. 2. Get to know Spring Framework<br />The Spring Framework: Overview<br />Topics:<br /><ul><li>What is Spring?
  3. 3. Spring modules
  4. 4. Why use Spring
  5. 5. Dependency injection / IOC in detail
  6. 6. Lab Work</li></li></ul><li>Get to know Spring Framework<br />What is Spring?<br />The Spring Framework is an open source application framework for the Java platform and .NET Framework (Spring.NET) <br /> <br />It is based on code published in Expert One-on-One J2EE Design and Development by Rod Johnson (Wrox, 2002).<br />“Spring is an open source framework created to address the complexity of enterprise application development. One of the chief advantages of the Spring framework is its layered architecture, which allows you to be selective about which of its components you use while also providing a cohesive framework for J2EE application development.<br />
  7. 7. Get to know Spring Framework<br />How does the Spring Framework looks like?<br />
  8. 8. Get to know Spring Framework<br />How does the Spring Framework looks like?<br />Each of the modules (or components) that comprise the Spring framework can stand on its own or be implemented jointly with one or more of the others. The functionality of each component is as follows:<br />The core container: The core container provides the essential functionality of the Spring framework. A primary component of the core container is the BeanFactory, an implementation of the Factory pattern. The BeanFactory applies the Inversion of Control (IOC) pattern to separate an application&apos;s configuration and dependency specification from the actual application code.<br />Spring context:The Spring context is a configuration file that provides context information to the Spring framework. The Spring context includes enterprise services such as JNDI, EJB, e-mail, internalization, validation, and scheduling functionality.<br />Spring AOP:The Spring AOP module integrates aspect-oriented programming functionality directly into the Spring framework, through its configuration management feature. As a result you can easily AOP-enable any object managed by the Spring framework. The Spring AOP module provides transaction management services for objects in any Spring-based application. With Spring AOP you can incorporate declarative transaction management into your applications without relying on EJB components.<br />
  9. 9. Get to know Spring Framework<br />How does the Spring Framework looks like?<br />Spring DAO:The Spring JDBC DAO abstraction layer offers a meaningful exception hierarchy for managing the exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the amount of exception code you need to write, such as opening and closing connections. Spring DAO&apos;s JDBC-oriented exceptions comply to its generic DAO exception hierarchy.<br />Spring ORM:The Spring framework plugs into several ORM frameworks to provide its Object Relational tool, including JDO, Hibernate, and iBatis SQL Maps. All of these comply to Spring&apos;s generic transaction and DAO exception hierarchies.<br />Spring Web module:The Web context module builds on top of the application context module, providing contexts for Web-based applications. As a result, the Spring framework supports integration with Jakarta Struts. The Web module also eases the tasks of handling multi-part requests and binding request parameters to domain objects.<br />Spring MVC framework:The MVC framework is a full-featured MVC implementation for building Web applications. The MVC framework is highly configurable via strategy interfaces and accommodates numerous view technologies including JSP, Velocity, Tiles, iText, and POI.<br />
  10. 10. Get to know Spring Framework<br />What does Spring Framework Offers: Summary<br />Inversion of Control container: configuration of application components and lifecycle management of Java objects<br />Aspect-oriented programming: enables implementation of cross-cutting routines<br />Data access: working with relational database management systems on the Java platform using JDBC and object-relational mapping tools<br />Transaction management: unifies several transaction management APIs and coordinates transactions for Java objects<br />Model-view-controller: a HTTP and Servlet-based framework providing hooks for extension and customization<br />Remote Access framework: configurative RPC-style export and import of Java objects over networks supporting RMI, CORBA and HTTP-based protocols including web services (SOAP)<br />Convention-over-configuration: a rapid application development solution for Spring-based enterprise applications is offered in the Spring Roo module<br />Batch processing: a framework for high-volume processing featuring reusable functions including logging/tracing, transaction management, job processing statistics, job restart, skip, and resource management<br />Authentication and authorization: configurable security processes that support a range of standards, protocols, tools and practices via the Spring Security sub-project (formerly Acegi).<br />Remote Management: configurative exposure and management of Java objects for local or remote configuration via JMX<br />Messaging: configurative registration of message listener objects for transparent message consumption from message queues via JMS, improvement of message sending over standard JMS APIs<br />Testing: support classes for writing unit tests and integration tests<br />
  11. 11. Get to know Spring Framework<br />Why use Spring?<br />Have you ever encountered these question?<br /><ul><li>Cant’ I have a simpler solution?
  12. 12. How can I handle my every changing requirements?
  13. 13. How can be the architecture flexible?
  14. 14. Can’t I have everything in components which can be verified independently?
  15. 15. Can I make a plug and play software?
  16. 16. How can the software components reusable and changeable?
  17. 17. Should we use EJB? As it makes the product complex, unpredictable and un-maintainable, non-portable and everything is framework committed.
  18. 18. …………….. And many more like these</li></ul>SPRING IS THE ANSWER!<br />
  19. 19. Get to know Spring Framework<br />Spring Framework’s Mission Statement<br />We believe that:<br /><ul><li>J2EE should be easier to use
  20. 20. It is best to program to interfaces, rather than classes. Spring reduces the complexity cost of using interfaces to zero.
  21. 21. JavaBeans offer a great way of configuring applications.
  22. 22. OO design is more important than any implementation technology, such as J2EE.
  23. 23. Checked exceptions are overused in Java. A platform shouldn't force you to catch exceptions you're unlikely to be able to recover from.
  24. 24. Testability is essential, and a platform such as Spring should help make your code easier to test.</li></ul>We aim that:<br /><ul><li>Spring should be a pleasure to use
  25. 25. Your application code should not depend on Spring APIs
  26. 26. Spring should not compete with good existing solutions, but should foster integration. (For example, JDO, Toplink, and Hibernate are great O/R mapping solutions. We don't need to develop another one.)</li></li></ul><li>Get to know Spring Framework<br />Are there any benefits of using spring?<br />Pure Java<br /><ul><li>Founded on POJO-based development </li></ul>Ordinary Java classes that follow no special APIs<br /><ul><li>Non-invasive for pre-existing POJOs
  27. 27. Rewards framework-independent business logic
  28. 28. Encourages new software to be written as POJOs
  29. 29. Results in highly portable, reusable, and verifiable software</li></ul>Less Custom Code<br /><ul><li>Expand capabilities with less code
  30. 30. Extensive and tested service abstractions
  31. 31. Email, JMS, JMX, JSF, JDBC, etc…
  32. 32. Replaces generic corporate libraries
  33. 33. Mitigates custom integration activities
  34. 34. Consistency eases integration because
  35. 35. spring platform is easy to use</li></ul>Turn-key solution<br />Spring components can be integrated quickly, with minimal effort and predictable results<br />
  36. 36. Get to know Spring Framework<br />Are there any benefits of using spring?<br />Helps only where needed<br /><ul><li>Modularity allows only relevant components to be introduced into the application.
  37. 37. For instance choose one:
  38. 38. Spring BeanFactory
  39. 39. Spring JMX
  40. 40. Spring JDBC
  41. 41. Framework can be interfaced in deep or shallow layers.
  42. 42. Interfaces are consistent at each layer</li></ul>Widely Available<br /><ul><li>Spring is integrated into numerous frameworks
  43. 43. Broad adoption possible because the container is portable and lightweight
  44. 44. The container itself is designed as a POJO
  45. 45. Integration without third-party support
  46. 46. Performance overhead is rarely a consideration as it is not EJB ;)</li></li></ul><li>Get to know Spring Framework<br />?<br />
  47. 47. Get to know Spring Framework<br />The Core Spring Module: Defining Beans and Dependency Injection<br />Topics:<br /><ul><li>Setting bean properties
  48. 48. Supplying constructor arguments
  49. 49. Using factory methods
  50. 50. Dependency injection
  51. 51. Supplying other beans as properties or constructor args</li></li></ul><li>Get to know Spring Framework<br />Spring Hello World: What will we do?<br />• Code a plain Java class model<br />– Use the interface pattern by coding a HelloWorld interface and a HelloWorldImpl implementation<br />• Configure the Spring IoC container<br />• Instantiate the Spring IoC container<br />• Acquire the object from the Spring IoC container<br />– The client must only have knowledge of the interface, HelloWorld<br />
  52. 52. Get to know Spring Framework<br />Spring Hello World: Create POJO<br />Create a interface HelloWorld<br />public interface HelloWorld {<br /> public void execute();<br />}<br />Create an implementing class HelloWorldImpl<br />public class HelloWorldImpl<br /> implements HelloWorld {<br /> public void execute() {<br />System.out.println(&quot;Hello World!&quot;);<br /> }<br />}<br />
  53. 53. Get to know Spring Framework<br />Spring Hello World: Spring IOC Configuration<br />&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br />&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;<br />xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;<br />xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans<br />http://www.springframework.org/schema/beans/spring-beans-2.5.xsd&quot;&gt;<br />&lt;bean id=&quot;helloWorld&quot;<br />class=&quot;HelloWorldImpl&quot; /&gt;<br />&lt;/beans&gt;<br />
  54. 54. Get to know Spring Framework<br />Spring Hello World: Execute<br />import org.springframework.beans.factory.*;<br />import org.springframework.context.support.*;<br />public class Main{<br />public static void main(String[] args) { <br />BeanFactorybeanFactory = new ClassPathXmlApplicationContext(<br />&quot;applicationContext.xml&quot;);<br />HelloWorldhelloWorld = (HelloWorld) beanFactory.getBean(&quot;helloWorld&quot;);<br />helloWorld.execute();<br />}<br />}<br />
  55. 55. Get to know Spring Framework<br />Spring Hello World: Output<br />Run the main class and you shall see “Hello World” printed.<br />
  56. 56. Spring Reference<br /><ul><li>http://www.springsource.org/
  57. 57. Top-level documentation page http://www.springframework.org/documentation</li></ul>• Wiki<br /> http://opensource.atlassian.com/confluence/spring<br />• Forum<br /> http://forum.springframework.org<br />• Books<br /> Spring Recipes. APress 2008<br /> Spring in Action. Manning 2007<br /> Agile Java Development with Spring, Hibernate and<br />Get to know Spring Framework<br />

×