Spring Framework Adam Waldal Senior Consultant. About me..  OPI is a leader in J2EE consulting with Relationships with BEA, IBM, Tibco, and many other.

Slides:



Advertisements
Similar presentations
Introduction to the Spring Framework
Advertisements

Apache Struts Technology
Spring, Hibernate and Web Services 13 th September 2014.
Enterprise Applications & Java/J2EE Technologies Dr. Douglas C. Schmidt Professor of EECS.
© 2005, Cornell University. Rapid Application Development using the Kuali Architecture (Struts, Spring and OJB) A Case Study Bryan Hutchinson
Pragmatic Application Building: Step by Step Jay Sissom Principal Systems Analyst Indiana University
The Spring Framework TM Rod Johnson Interface21. Spring framework goals Make J2EE easier to use Address end-to-end requirements rather than one tier Eliminate.
The Spring Framework: A brief introduction to Inversion of Control James Brundege
Last Update: 5/15/061 Spring J2EE Framework Ram A. Rao May 15 th ‘05.
Intro to Spring CJUG - January What is Spring? “The Spring framework provides central transaction control of various objects.” This means that any.
An Introduction to Hibernate Matt Secoske
The Spring Framework A quick overview. The Spring Framework 1. Spring principles: IoC 2. Spring principles: AOP 3. A handful of services 4. A MVC framework.
UNIT-V The MVC architecture and Struts Framework.
Java Frameworks Indy Java Users Group January 29, 2003.
JDBC Session 5 Tonight: Data Access Patterns 1.J2EE Architecture & Design Patterns 2.The Data Access Tier 3.Data Access Patterns –DataAccessObject (DAO)
NetArchive Suite Workshop 2011 Technical Track - Code refactoring with the Spring Framework.
Spring Framework. Spring Overview Spring is an open source layered Java/J2EE application framework Created by Rod Johnson Based on book “Expert one-on-one.
Introduction to the Spring Framework By: Nigusse A. Duguma Kansas State university Department of Computer Science Nov 20, 2007.
Copyright 2006, Codeguild, Inc Spring Framework Fundamentals March, 2006 Larry Hamel Codeguild, Inc.
Spring Overview, Application demo -Midhila Paineni 09/23/2011 Spring Overview, Application demo9/8/20151.
Spring. Spring Overview Spring Container Concepts Spring and AOP Spring and Data Access Managing Transactions and Resources Remoting and Accessing Enterprise.
The Spring Framework Training Get to know Spring Framework Rohit Prabhakar
Introduction to the Spring Framework Rajesh. Spring Mission Statement J2EE should be easier to use OO design is more important than any implementation.
Copyright © 2005 Finetix LLC All Rights Reserved 0 SpringFramework.Java Developer Session Solomon Duskis The Peer Frameworks Series -.Net and Java.
95-843: Service Oriented Architecture 1 Master of Information System Management Service Oriented Architecture Lecture 10: Service Component Architecture.
Entity Java Beans Jorg Janke Open Source ERP & CRM.
OpusCollege and the use of Spring and iBatis
Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development.
Spring core v3.x Prepared by: Nhan Le. History v3.0 Spring Expression Language Java based bean metadata v3.1 Cache Abstraction Bean Definition Profile.
Dependency Injection in Action Jan Västernäs. CADEC2006, DI, Slide 2 Copyright 2006, Callista Enterprise AB Agenda (DI=Dependency Injection) Background.
PicoContainer Presented by: Jim O’Hara Ed Kausmeyer Jingming Zhang.
SAMANVITHA RAMAYANAM 18 TH FEBRUARY 2010 CPE 691 LAYERED APPLICATION.
Opus College - overview. OpusCollege - background First project: ICT Capacity Building Mozambican Higher Education Institutions Partners: RUG Groningen,
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
Spring Framework. Spring Overview Spring is an open source layered Java/J2EE application framework Created by Rod Johnson Based on book “Expert one-on-one.
Introduction to Spring Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic.
Source: Peter Eeles, Kelli Houston, and Wojtek Kozaczynsky, Building J2EE Applicationa with the Rational Unified Process, Addison Wesley, 2003 Prepared.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Montreal CRIM Workshop Introduction to Spring Framework,
A Presentation By V AIBHAV S AHARAN Web-enHanced Information Management COMS E6125.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Spring Remoting Simplifying.
Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications.
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions Buenos Aires, June 2009.
Java EE Patterns Dan Bugariu.  What is Java EE ?  What is a Pattern ?
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
Spring and DWR Frameworks for Rich Web Enterprise Application Thomas Wiradikusuma Presentation to the 20 th.
1 Spring Framework April, 2012 Lam Ho Lam To. © 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2 1.Spring Overview 2.Framework.
JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Kansas City Java User’s Group Jason W. Bedell July 12, 2006
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions Buenos Aires, June 2009.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Overview of the Spring Framework Introducing.
Enterprise JavaBeans: Fundamentals. EJB Fundamentals(c)CDAC(Formerly NCST)2 Contents Introduction Technology Overview EJB Architecture EJB Specification.
EJB Enterprise Java Beans JAVA Enterprise Edition
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions and Spring MVC Buenos Aires, June 2009.
Apache Struts Technology A MVC Framework for Java Web Applications.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Montreal CRIM Workshop Introduction to Spring Framework.
Leveraging ColdSpring to build a robust Flex applications Chris Scott, Cynergy Systems.
J2EE Platform Overview (Application Architecture)
J2EE Lecture 6: Spring – IoC and Dependency Injection
Unit 6-Chapter 2 Struts.
Enterprise Application Architecture
By Ru Shen Department of Computer Science UAlbany, 2008
Intro to Spring CJUG - January 2013.
The Model Layer What is Model?
Introduction to Spring Framework and Dependency Injection
SAMANVITHA RAMAYANAM 18TH FEBRUARY 2010 CPE 691
Developing and testing enterprise Java applications
Leveraging ColdSpring To Make Better Applications
Aspect Oriented Programming
Presentation transcript:

Spring Framework Adam Waldal Senior Consultant

About me..  OPI is a leader in J2EE consulting with Relationships with BEA, IBM, Tibco, and many other vendors.  Technical Project Lead for OPI  Agile Software Practitioner  Speaker for BEA User Group on Spring

Spring Framework Mission  We believe that: –J2EE should be easier to use –It's best to program to interfaces, rather than classes. Spring reduces the complexity cost of using interfaces to zero. –JavaBeans offer a great way of configuring applications. –OO design is more important than any implementation technology, such as J2EE. –Checked exceptions are overused in Java. A framework shouldn't force you to catch exceptions you're unlikely to be able to recover from. –Testability is essential, and a framework such as Spring should help make your code easier to test.  We aim that: –Spring should be a pleasure to use –Your application code should ''not'' depend on Spring APIs –Spring should not compete with good existing solutions, but should foster integration. (For example, JDO and Hibernate are great O/R mapping solutions. We don't need to develop another one.)

Overview  IOC and Dependency Injection  Lightweight Containers explained  Description of Spring as a framework  Description of the BeanFactory  AOP explained  AOP in Spring overview  Why or Why not use Spring?  Example Application: jPetstore

IOC Inversion of Control  IOC Definition “Giving control to an object over who it calls, but not who calls it.” – Me “IOC is this“ – Rod Johnson

Two types of IOC common to J2EE  Dependency Lookup EJB and Apache Avalon - The coarse-grain beans are left looking up dependencies it needs. –“In J2EE, JNDI is the glue that holds J2EE applications together…” IBM  Dependency Injection Spring and Pico – Factories create beans with all the dependencies set on the bean. –In Spring that glue is externalized so business classes don’t have to worry about how or what they need to glue together.

Setter and Constructor Injection // Example of Setter Injection package eg; public class ExampleBean { private AnotherBean beanOne; private YetAnotherBean beanTwo; public void setBeanOne(AnotherBean b) { beanOne = b; } public void setBeanTwo(YetAnotherBean b) { beanTwo = b; } } // Example of Constructor Injection (This is the typical Spring usage) public class ExampleBean { private AnotherBean beanOne; private YetAnotherBean beanTwo; public ExampleBean (AnotherBean a, YetAnotherBean b){ this.beanOne = a; this.beanTwo = b; } …Business Methods }

My Description of Spring  Spring is a glue framework that is gives an easy way of configuring and resolving dependencies throughout the J2EE stack. It has MVC, AOP, declarative management of beans and services, JDBC, JMS, and other useful abstractions.  Spring ties many other technologies together in a consistent approach.  The light weight container only used for the service layer is enough to provide a business case for using Spring.  Spring also provides declarative access to enterprise services via AOP (Aspect Oriented Programming). J2EE services exposed through aspects,usually hidden behind an EJB container, helps to facilitate testing and consequently ease of development.  The added ease of development and maintenance make the value proposition presented with Spring very attractive to most companies.

Spring features Below is a list of some of the features in Spring. –MVC Framework implemented with interfaces and IOC(another presentation) –IOC (Inversion of Control) Container to facilitate Dependency Injection –Application Context which is an implementation of BeanFactory –AOP Framework for accessing J2EE service declaratively –JDBC and DAO layer Abstraction (another presentation) –Exception Handling Framework for Persisting proprietary exceptions ( another presentation ) –JMS producer, consumer abstractions, and conversion

Spring API’s

Bean Factory Configuration

Lightweight Containers Lightweight is maybe mistaken to mean less than an Enterprise container. Simplicity is actually often better than the complexity to handle the worst in every scenario. The ability to scale up and down is more desirable in most applications. Lightweight should be taken to mean flexible, pluggable, and configurable. The idea that the simplest solution that can work, should be supported by the container as well. Container Services  Lifecycle management  Lookup  Configuration  Dependency Resolution

Criteria for a Lightweight Container Lightweight Criteria  Manage application code without imposing dependency on the container itself.  Quick startup  No special deployment  Flexibility to run in different environments  Easy management and low overhead to allow management of fine as well as coarse grained components.

Struts Example using WebApplicationContext package org.springframework.samples.jpetstore.web.struts; import javax.servlet.ServletContext; import org.apache.struts.action.Action; import org.apache.struts.action.ActionServlet; import org.springframework.samples.jpetstore.domain.logic.PetStoreFacade; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; public abstract class BaseAction extends Action { private PetStoreFacade petStore; public void setServlet(ActionServlet actionServlet) { super.setServlet(actionServlet); ServletContext servletContext = actionServlet.getServletContext(); WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); this.petStore = (PetStoreFacade) wac.getBean("petStore"); } protected PetStoreFacade getPetStore() { return petStore; }

Child of BaseAction package org.springframework.samples.jpetstore.web.struts; import javax.servlet.http.HttpServletRequest; … public class AddItemToCartAction extends BaseAction { public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { CartActionForm cartForm = (CartActionForm) form; Cart cart = cartForm.getCart(); String workingItemId = cartForm.getWorkingItemId(); if (cart.containsItemId(workingItemId)) { cart.incrementQuantityByItemId(workingItemId); } else { // isInStock is a "real-time" property that must be updated // every time an item is added to the cart, even if other // item details are cached. boolean isInStock = getPetStore().isItemInStock(workingItemId); Item item = getPetStore().getItem(workingItemId); cartForm.getCart().addItem(item, isInStock); } return mapping.findForward("success"); }

Spring Controller package org.springframework.samples.jpetstore.web.spring; … import org.springframework.samples.jpetstore.domain.logic.PetStoreFacade; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import org.springframework.web.util.WebUtils; public class AddItemToCartController implements Controller { private PetStoreFacade petStore; public void setPetStore(PetStoreFacade petStore) { this.petStore = petStore; } public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { Cart cart = (Cart) WebUtils.getOrCreateSessionAttribute(request.getSession(), "sessionCart", Cart.class); String workingItemId = request.getParameter("workingItemId"); if (cart.containsItemId(workingItemId)) { cart.incrementQuantityByItemId(workingItemId); } else { boolean isInStock = this.petStore.isItemInStock(workingItemId); Item item = this.petStore.getItem(workingItemId); cart.addItem(item, isInStock); } return new ModelAndView("Cart", "cart", cart); }

AOP Description  AOP decomposes a system into aspects or concerns, rather than objects. An example of a concern in an application would be logging, security, or transaction management.  EJB declarative services are discrete example of aspects.  Often in OO systems there is code bloat and duplication from such concerns.  Code duplication is a sign there is something wrong with the solution.  There are some cases in some systems where OO does not provide a clean solution.  It is capable of using either dynamic proxies or dynamic bytecode generation with CGLIB. This is also used in Hibernate.  Spring, AspectJ, Nanning

AOP in Spring  Spring implements AOP in the same consistent way it deals with bean definitions in a BeanFactory.  Transactions for JDBC  Transactions for JTA  Transaction Interceptor

AOP in Spring  Definitions: –Aspect - An application wide concern that is often duplicated in many classes, that could be implemented before, after, or upon failure across a group of methods. –JointPoint - A join of methods across which an aspect can be implemented. –Spring allows method interception. This means when a method is called the framework can attach functionality. –Pointcut - Description of the collection of methods for which advice is to be applied –Introduction - Adding methods or properties to a class with advice. –AOP Proxies - Surrogate object that invokes advice and advises the invoked class

Declarative Transactions with AOP  Provides a consistent programming model across different transaction APIs such as JTA, JDBC, Hibernate,  iBATIS Database Layer and JDO.  Provides a simpler, easier to use, API for programmatic transaction management than most of these transaction APIs  Integrates with the Spring data access abstraction  Supports Spring declarative transaction management PROPAGATION_REQUIRED PROPAGATION_REQUIRED,readOnly <!-- -->

TransactionManager Abstraction Spring Transaction Strategy Interface: public interface PlatformTransactionManager { TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException; void commit(TransactionStatus status) throws TransactionException; void rollback(TransactionStatus status) throws TransactionException; } JDBC - JTA - Hibernate - <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">

jPetstore Example Online at springframework.org  Petclinic is another version of the petstore app with Spring, and a number of different O/R and jdbc solutions

Why use Spring?  Spring is a clear choice in a web application with a tiered architecture.  Spring gives good abstractions for integrating Hibernate. Use Spring and Hibernate together if O/R is necessary.  If using JDBC spring is a must.  If you are building a stateless service layer for any type of view Spring adds value.  If you want to simplify configuration and testing us Spring.  If you are using EJB still use the Spring Bean Factory for managing fine grained objects.

Why not use Spring?  If you are already using EJB on a project and have a infrastructure built up around it that you think works. (Still look at Spring for managing a DAO layer or using the Template method pattern for JDBC or Hibernate Templates.)  Always evaluate any solution and only apply a new technology if it makes sense for the application not for the sake of the technology.

OPI using Spring  We are currently using Spring in two clients  Evaluating replace of SLSB in favor of Spring with Hibernate  Our approach to technology selection aligns well with the principals held by the Spring development team

Resources     Rod Johnson’s two books : –J2EE without EJB –J2EE Design and Development (co-author Juergen Hoeller)  Better, Faster, Lighter Java by Bruce Tate, Justin Gehtland  Spring Live by Matt Raible  Me,