An Introduction to the  Spring Framework
What is the Spring Framework? <ul><li>Spring is a Lightweight  Application  Framework  </li></ul><ul><li>Where Struts, Web...
Spring == J2EE Application Server? <ul><li>Spring is NOT a J2EE application server </li></ul><ul><li>Spring can integrate ...
Before Struts <ul><li>Before Struts, everyone wrote their own front controllers or put their controller logic in JSP </li>...
Spring Can Help! <ul><li>Spring brings a consistent structure to your entire application </li></ul><ul><li>Spring provides...
Cont <ul><li>Just as Struts did on the web tier, we can realize huge productivity gains by not having to write the common ...
The Spring Framework Mission Statement <ul><li>J2EE should be easier to use </li></ul><ul><li>It's best to program to inte...
Spring Framework Mission Statement (continued) <ul><li>Your application code should  not  depend on Spring APIs </li></ul>...
Spring Architecture
Spring is Non-Invasive <ul><li>What does that mean? </li></ul><ul><li>You are not forced to import or extend any Spring AP...
Spring Core <ul><li>At it’s core, Spring provides: </li></ul><ul><li>An Inversion of Control Container </li></ul><ul><ul><...
Spring Core (Continue) <ul><li>Spring at it’s core, is a framework for wiring up your entire application </li></ul><ul><li...
BeanFactories <ul><li>A  BeanFactory  is typically configured in an XML file with the root element: <beans> </li></ul><ul>...
BeanFactories <ul><li>By default, beans are treated as singletons </li></ul><ul><li>Can also be prototypes </li></ul><ul><...
Property Values for BeanFactories <ul><li>Strings and Numbers </li></ul><ul><li>Arrays and Collections </li></ul><property...
Property Values for BeanFactories (continued) <ul><li>The real magic comes in when you can set </li></ul><ul><li>a propert...
Dependency Injection (Inversion of Control) <ul><li>Complicated sounding terms for a fairly simple concept </li></ul><ul><...
Dependency Injection (Inversion of Control) <ul><li>Eliminates lookup code from within your application </li></ul><ul><li>...
A Very Special BeanFactory: the ApplicationContext <ul><li>An  ApplicationContext  is a  BeanFactory , but adds “framework...
AOP (Aspect-Oriented Programming) <ul><li>AOP decomposes a system into concerns, instead of objects. </li></ul><ul><li>Dea...
AOP (Aspect-Oriented Programming) <ul><li>AOP enables the delivery of services to POJOs </li></ul><ul><li>Spring provides ...
Service Abstraction Layers <ul><li>Spring provides abstraction for: </li></ul><ul><li>Transaction Management </li></ul><ul...
Service Abstraction Layers <ul><li>Benefits: </li></ul><ul><li>No implicit contracts with JNDI, etc. </li></ul><ul><li>Ins...
Spring on the Web Tier <ul><li>Spring integrates nicely with Struts, WebWork, JSF, Tapestry, Velocity and other web framew...
Spring on the Web Tier – Spring MVC <ul><li>MVC web application framework built on core Spring functionality </li></ul><ul...
Spring on the Web Tier – Spring MVC (Cont) <ul><li>The Spring MVC Framework offers a simple interface based infrastructure...
Spring MVC – Key Interfaces <ul><li>Controller  ( org.springframework.web.servlet.mvc.Controller ) </li></ul><ul><ul><li>M...
Spring on the Web Tier: Integration with Other Frameworks <ul><li>Spring integrates nicely with other web frameworks with ...
Spring ORM <ul><li>ORM Module in Spring Relates With the Database access </li></ul><ul><li>Provides Integration Layer for ...
Spring DAO <ul><li>Spring DAO (Data access object) module  </li></ul><ul><li>supports for standardizing data access  </li>...
Upcoming SlideShare
Loading in...5
×

Spring Framework

3,153

Published on

Introduction to SPRING FRAMEWORK

Published in: Education, Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,153
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
349
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Transcript of "Spring Framework"

  1. 1. An Introduction to the Spring Framework
  2. 2. What is the Spring Framework? <ul><li>Spring is a Lightweight Application Framework </li></ul><ul><li>Where Struts, WebWork and others can be considered Web frameworks, Spring addresses all tiers of an application </li></ul><ul><li>Spring provides the plumbing so that you don’t have to! </li></ul>
  3. 3. Spring == J2EE Application Server? <ul><li>Spring is NOT a J2EE application server </li></ul><ul><li>Spring can integrate nicely with J2EE application servers (or any Java environment) </li></ul><ul><li>Spring can, in many cases, elegantly replace services traditionally provided by J2EE application servers </li></ul>
  4. 4. Before Struts <ul><li>Before Struts, everyone wrote their own front controllers or put their controller logic in JSP </li></ul><ul><li>After Struts, the custom front controllers could be thrown out </li></ul><ul><ul><li>Developers focus on solving business problems </li></ul></ul><ul><ul><li>Productivity Gain! </li></ul></ul><ul><li>But with Struts (and most of the other web frameworks) you still have to write your own business delegates or service layers… </li></ul>
  5. 5. Spring Can Help! <ul><li>Spring brings a consistent structure to your entire application </li></ul><ul><li>Spring provides a consistent way to glue your whole application together </li></ul><ul><li>Spring provides elegant integration points with standard interfaces </li></ul><ul><li>Hibernate </li></ul><ul><li>JDO </li></ul><ul><li>TopLink </li></ul><ul><li>EJB </li></ul><ul><li>RMI </li></ul><ul><li>JNDI </li></ul><ul><li>JMS </li></ul><ul><li>Web Services </li></ul><ul><li>Struts etc. </li></ul>
  6. 6. Cont <ul><li>Just as Struts did on the web tier, we can realize huge productivity gains by not having to write the common integration points across your application </li></ul>
  7. 7. The Spring Framework Mission Statement <ul><li>J2EE should be easier to use </li></ul><ul><li>It's best to program to interfaces, rather than classes. Spring reduces the complexity cost of using interfaces to zero. </li></ul><ul><li>JavaBeans offer a great way of configuring applications. </li></ul><ul><li>OO design is more important than any implementation technology, such as J2EE. </li></ul><ul><li>Testability is essential, and a framework such as Spring should help make your code easier to test. </li></ul>
  8. 8. Spring Framework Mission Statement (continued) <ul><li>Your application code should not depend on Spring APIs </li></ul><ul><li>Spring should not compete with good existing solutions, but Used for integration. (For example, JDO and Hibernate are great O/R mapping solutions. We don't need to develop another one.) </li></ul>
  9. 9. Spring Architecture
  10. 10. Spring is Non-Invasive <ul><li>What does that mean? </li></ul><ul><li>You are not forced to import or extend any Spring APIs </li></ul><ul><li>An invasive API takes over your code. </li></ul><ul><li>Anti-patterns: </li></ul><ul><ul><li>EJB forces you to use JNDI </li></ul></ul><ul><ul><li>Struts forces you to extend Action </li></ul></ul>
  11. 11. Spring Core <ul><li>At it’s core, Spring provides: </li></ul><ul><li>An Inversion of Control Container </li></ul><ul><ul><li>Also known as Dependency Injection </li></ul></ul><ul><ul><li>Setter Injection (Injection via Java Bean Setters) </li></ul></ul><ul><ul><li>Constructor Injection (Injection via Constructor arguments) </li></ul></ul><ul><ul><li>An AOP Framework </li></ul></ul><ul><ul><li>Spring provides a proxy-based AOP framework </li></ul></ul><ul><ul><li>You can alternatively integrate with AspectJ or AspectWerkz </li></ul></ul><ul><li>A Service Abstraction Layer </li></ul><ul><ul><li>Consistent integration with various standard and 3 rd party APIs </li></ul></ul><ul><li>These together enable you to write powerful, scalable applications using POJOs. </li></ul>
  12. 12. Spring Core (Continue) <ul><li>Spring at it’s core, is a framework for wiring up your entire application </li></ul><ul><li>BeanFactories are the heart of Spring </li></ul>
  13. 13. BeanFactories <ul><li>A BeanFactory is typically configured in an XML file with the root element: <beans> </li></ul><ul><li>The XML contains one or more <bean> elements </li></ul><ul><ul><li>id (or name) attribute to identify the bean </li></ul></ul><ul><ul><li>class attribute to specify the fully qualified class </li></ul></ul>
  14. 14. BeanFactories <ul><li>By default, beans are treated as singletons </li></ul><ul><li>Can also be prototypes </li></ul><ul><li>Here is an example: </li></ul><beans> <bean id=“widgetService” class=“com.zabada.base.WidgetService”> <property name=“poolSize”> <!—-property value here--> </property> </bean> </beans> The bean’s ID The bean’s fully- qualified classname Maps to a setPoolSize() call
  15. 15. Property Values for BeanFactories <ul><li>Strings and Numbers </li></ul><ul><li>Arrays and Collections </li></ul><property name=“size”><value>42</value></property> <property name=“name”><value>Jim</value></property> <property name=“hobbies”> <list> <value>Basket Weaving</value> <value>Break Dancing</value> </list> </property>
  16. 16. Property Values for BeanFactories (continued) <ul><li>The real magic comes in when you can set </li></ul><ul><li>a property on a bean that refers to another </li></ul><ul><li>bean in the configuration: </li></ul><ul><li>This is the basic concept </li></ul><ul><li>of Inversion of Control </li></ul><bean name=“widgetService” class=“com.zabada.base.WidgetServiceImpl”> <property name=“widgetDAO”> <ref bean=“myWidgetDAO”/> </property> </bean> calls setWidgetDAO(myWidgetDAO) where myWidgetDAO is another bean defined in the configuration
  17. 17. Dependency Injection (Inversion of Control) <ul><li>Complicated sounding terms for a fairly simple concept </li></ul><ul><li>The “Hollywood Principle”: Don’t call me, I’ll call you </li></ul><ul><li>Dependencies used from within a bean aren’t asked for outwardly, but are injected into the bean by the container </li></ul>
  18. 18. Dependency Injection (Inversion of Control) <ul><li>Eliminates lookup code from within your application </li></ul><ul><li>Allows for pluggablity and hot swapping </li></ul><ul><li>Promotes good OO design </li></ul><ul><li>Enables reuse of existing code </li></ul><ul><li>Makes your application extremely testable </li></ul>
  19. 19. A Very Special BeanFactory: the ApplicationContext <ul><li>An ApplicationContext is a BeanFactory , but adds “framework” features such as: </li></ul><ul><ul><li>i18n messages </li></ul></ul><ul><ul><li>Event notifications </li></ul></ul><ul><li>This is what you will probably most often use in your Spring applications </li></ul>
  20. 20. AOP (Aspect-Oriented Programming) <ul><li>AOP decomposes a system into concerns, instead of objects. </li></ul><ul><li>Deals with &quot;aspects&quot; that cross-cut across the code and can be difficult or impossible to modularize with OOP </li></ul><ul><li>The most common example given is logging </li></ul><ul><ul><li>Code for doing logging typically must be scattered all over a system </li></ul></ul><ul><ul><li>With AOP, you can declare, for example, that a system should write a log record at the beginning and end of all method invocations. </li></ul></ul>
  21. 21. AOP (Aspect-Oriented Programming) <ul><li>AOP enables the delivery of services to POJOs </li></ul><ul><li>Spring provides pre-packaged AOP services: </li></ul><ul><ul><li>Declarative Transaction Management </li></ul></ul><ul><ul><li>Security </li></ul></ul><ul><ul><li>Logging </li></ul></ul><ul><li>You can write custom AOP services for: </li></ul><ul><ul><li>Auditing </li></ul></ul><ul><ul><li>Caching </li></ul></ul><ul><ul><li>Custom security </li></ul></ul>
  22. 22. Service Abstraction Layers <ul><li>Spring provides abstraction for: </li></ul><ul><li>Transaction Management </li></ul><ul><ul><li>JTA, JDBC, others </li></ul></ul><ul><li>Data Access </li></ul><ul><ul><li>JDBC, Hibernate, JDO, TopLink, iBatis </li></ul></ul><ul><li>Email </li></ul><ul><li>Remoting </li></ul><ul><ul><li>EJB, Web Services, RMI, Hessian/Burlap </li></ul></ul>
  23. 23. Service Abstraction Layers <ul><li>Benefits: </li></ul><ul><li>No implicit contracts with JNDI, etc. </li></ul><ul><li>Insulates you from the underlying APIs </li></ul><ul><li>Greater reusability </li></ul><ul><li>Spring abstractions always consist of interfaces </li></ul><ul><li>This makes testing simpler </li></ul><ul><li>For data access, Spring uses a generic transaction infrastructure and DAO exception hierarchy that is common across all supported platforms </li></ul>
  24. 24. Spring on the Web Tier <ul><li>Spring integrates nicely with Struts, WebWork, JSF, Tapestry, Velocity and other web frameworks </li></ul><ul><li>Spring also provides it’s own web framework, Spring Web MVC </li></ul>
  25. 25. Spring on the Web Tier – Spring MVC <ul><li>MVC web application framework built on core Spring functionality </li></ul><ul><li>MVC dispatcher framework </li></ul><ul><li>is highly configurable via strategy interfaces and accommodates multiple view technologies Like </li></ul><ul><li>JSP, Tiles, Velocity, FreeMarker, iText </li></ul><ul><li>MVC comes in a Servlet edition working with the underlying environment </li></ul>
  26. 26. Spring on the Web Tier – Spring MVC (Cont) <ul><li>The Spring MVC Framework offers a simple interface based infrastructure for handing web MVC architectures </li></ul><ul><li>Spring MVC components are treated as first-class Spring beans </li></ul><ul><ul><li>Other Spring beans can easily be injected into Spring MVC components </li></ul></ul><ul><ul><li>Spring MVC components are easy to test </li></ul></ul>
  27. 27. Spring MVC – Key Interfaces <ul><li>Controller ( org.springframework.web.servlet.mvc.Controller ) </li></ul><ul><ul><li>Must implement ModelAndView handleRequest(request,response) </li></ul></ul><ul><ul><li>This is the base controller interface, comparable to the notion of a Struts Action. </li></ul></ul><ul><li>View ( org.springframework.web.servlet.mvc.View ) </li></ul><ul><ul><li>Must implement void render( model, request, response) </li></ul></ul><ul><ul><li>This is the MVC view for a web interaction. Implementations are responsible for rendering content, and exposing the model. </li></ul></ul><ul><li>Model </li></ul><ul><ul><li>To complete the MVC trio, note that the model is typically handled as a java.util.Map which is returned with the view </li></ul></ul><ul><ul><li>the values of the model are available, for example in a JSP, using a <jsp:useBean/> where the id corresponds to the key value in the Map </li></ul></ul>
  28. 28. Spring on the Web Tier: Integration with Other Frameworks <ul><li>Spring integrates nicely with other web frameworks with two methodologies: </li></ul><ul><ul><li>Look up Spring beans within Controllers/Actions via the convenience static method: WebApplicationContextUtils.getWebApplicationContext( servletContext).getBean(“beanName”) </li></ul></ul><ul><ul><li>Configure the Controllers/Actions for the web framework in a Spring BeanFactory and then use Spring provided proxies in the actual web framework configuration </li></ul></ul><ul><ul><ul><li>When available, this methodology is preferred </li></ul></ul></ul><ul><ul><ul><li>This approach lets you design your Controllers/Actions with dependency injection and makes your Controller/Actions more testable </li></ul></ul></ul>
  29. 29. Spring ORM <ul><li>ORM Module in Spring Relates With the Database access </li></ul><ul><li>Provides Integration Layer for Popular </li></ul><ul><li>Object Relating Mapping API’s including </li></ul><ul><li>JDO , Hibernate etc </li></ul>
  30. 30. Spring DAO <ul><li>Spring DAO (Data access object) module </li></ul><ul><li>supports for standardizing data access </li></ul><ul><li>work using Technologies like </li></ul><ul><li>JDBC </li></ul><ul><li>Hibernate </li></ul><ul><li>JDO, etc </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×