Spring. Spring Overview Spring Container Concepts Spring and AOP Spring and Data Access Managing Transactions and Resources Remoting and Accessing Enterprise.

Slides:



Advertisements
Similar presentations
Introduction to the Spring Framework
Advertisements

Spring 3.0 MVC - Introduction By, Srinivas Reddy.S
Spring, Hibernate and Web Services 13 th September 2014.
Introduction to the Spring Framework University of Kansas January 2009 This presentation and example application are available at
Introduction to Spring Matt Wheeler. Notes This is a training NOT a presentation Please ask questions Prerequisites – Introduction to Java Stack – Basic.
Next Generation Node (NGN) Technical Overview April 2007.
Review Amit Shabtay. March 3rd, 2004 Object Oriented Design Course 2 Review What have we done during the course? Where to learn more? What is for the.
© 2005, Cornell University. Rapid Application Development using the Kuali Architecture (Struts, Spring and OJB) A Case Study Bryan Hutchinson
Application Architectures Vijayan Sugumaran Department of DIS Oakland University.
Address - #22, 1 st Floor, Station View Road, Kodambakkam, Chennai JTech Soft Solutions Website:
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.
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.
Spring Framework Adam Waldal Senior Consultant. About me..  OPI is a leader in J2EE consulting with Relationships with BEA, IBM, Tibco, and many other.
Spring Paul Jensen Principal, Object Computing Inc.
UNIT-V The MVC architecture and Struts Framework.
Java Frameworks Indy Java Users Group January 29, 2003.
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.
Agenda What is Hibernate Spring Integration Questions Overview
BEST PRACTICES - Java By Configuration Use global-forwards/results Helps to avoid duplicate jsp files and redundancy forward mapping.
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 © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
Copyright (C) 2009 by Abdelmonaim Remani. All rights reserved. By Abdelmonaim Remani Polymathic-coder.com Silicon Valley Code.
OpusCollege and the use of Spring and iBatis
Dependency Injection in Action Jan Västernäs. CADEC2006, DI, Slide 2 Copyright 2006, Callista Enterprise AB Agenda (DI=Dependency Injection) Background.
Text 16 de mayo de 2009 Spring Framework Part I. Dependency Injection Buenos Aires, May 2009.
Opus College - overview. OpusCollege - background First project: ICT Capacity Building Mozambican Higher Education Institutions Partners: RUG Groningen,
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,
Introduction to Web Dimitar Nenchev Ivan Nakov
A Presentation By V AIBHAV S AHARAN Web-enHanced Information Management COMS E6125.
Spring Framework. About spring Spring is the most popular application development framework for enterprise Java. Millions of developers around the world.
Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications.
INTEGRATION OF BACKBONE.JS WITH SPRING 3.1. Agenda New Features and Enhancements in Spring 3.1 What is Backbone.js and why I should use it Spring 3.1.
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.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
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.
1 Copyright © 2004, Oracle. All rights reserved. Oracle Application Development 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
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.
Spring Framework BT Team 25/02/ Spring A lightweight framework that addresses each tier in a Web application. Presentation layer – An MVC framework.
Spring JDBC Dima Ionut Daniel. Contents What is Spring JDBC? Overview Spring JDBC Core SQL Exceptions Database Connection Batch Operations Handling BLOB/CLOB.
Singleton Academy, Pune. Course syllabus Singleton Academy Pune – Course Syllabus1.
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions and Spring MVC Buenos Aires, June 2009.
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.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
J2EE Platform Overview (Application Architecture)
J2EE Lecture 6: Spring – IoC and Dependency Injection
Unit 6-Chapter 2 Struts.
By Ru Shen Department of Computer Science UAlbany, 2008
Intro to Spring CJUG - January 2013.
The Model Layer What is Model?
JavaServer Faces: The Fundamentals
Developing and testing enterprise Java applications
Leveraging ColdSpring To Make Better Applications
Presentation transcript:

Spring

Spring Overview Spring Container Concepts Spring and AOP Spring and Data Access Managing Transactions and Resources Remoting and Accessing Enterprise Services Spring Web Framework Integrating with Struts DAO and LDAP support

Spring Overview Spring is a Lightweight Application Framework Spring Promotes loose coupling through Inversion of Control (IoC) Spring comes with rich support for Aspect-Oriented Programming.

Spring Overview “Lightweight Container” Very loosely coupled Components widely reusable and separately packaged Created by Rod Johnson Based on “Expert one-on-one J2EE Design and Development” Currently on version 1.1.1

Why Use Spring? Wiring of components (Dependency Injection) Promotes/simplifies decoupling, design to interfaces Declarative programming without J2EE Easily configured aspects, esp. transaction support

Why Use Spring? Conversion of checked exceptions to unchecked (Or is this a reason not to use it?) Not an all-or-nothing solution Extremely modular and flexible Well designed Easy to extend Many reusable classes

Architectural benefits Spring can effectively organize your middle tier objects, whether or not you choose to use EJB. Spring's configuration management services can be used in any architectural layer, in whatever runtime environment. Spring can use AOP to deliver declarative transaction management without using an EJB container.

Architectural benefits Spring provides a consistent framework for data access, whether using JDBC or an O/R mapping product such as TopLink, Hibernate Spring provides a consistent, simple programming model in many areas JDBC, JMS, JavaMail, JNDI and many other important API’s.

Spring Framework The Spring framework is a layered architecture consisting of seven well-defined modules. The Spring modules are built on top of the core container, which defines how beans are created, configured and managed.

Spring Framework

Core container Provides the essential functionality of the Spring framework. Primary component of the core container is the BeanFactory, an implementation of the Factory pattern. BeanFactory applies the Inversion of Control (IOC) pattern to separate an application's configuration and dependency specification from the actual application code.

Spring Framework Spring context Spring context is a configuration file that provides context information to the Spring framework. The Spring context includes enterprise services such as JNDI, EJB, , validation, and scheduling functionality.

Spring Framework Spring AOP The Spring AOP integrates aspect-oriented functionality directly into the Spring framework. Provides transaction management services for objects in any Spring-based application. Incorporates declarative transaction management capabilities into applications without relying on EJB components.

Spring Framework Spring DAO Spring JDBC DAO abstraction layer offers 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's JDBC-oriented exceptions comply to its generic DAO exception hierarchy.

Spring Framework Spring ORM The Spring framework plugs into several ORM frameworks to provide its Object Relational tool, including JDO and Hibernate. All of these comply to Spring's generic transaction and DAO exception hierarchies.

Spring Framework Spring Web module The Web context module builds on top of the application context module, providing contexts for Web-based applications. The Web module also eases the tasks of handling multi-part requests and binding request parameters to domain objects.

Spring MVC framework The Model-View-Controller (MVC) framework 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 and iText.

Aspect Oriented Programming Aspect-oriented programming, or AOP, is a programming technique that allows programmers to modularize crosscutting concerns, or behavior that cuts across the typical divisions of responsibility, such as logging and transaction management.

BeanFactory Usage InputStream is = new FileInputStream("beans.xml"); XmlBeanFactory factory = new XmlBeanFactory(is); MyBeanClass bean = (MyBeanClass)factory.getBean(“myBean”); ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml"); MyBeanClass bean = (MyBeanClass)ctx.getBean(“myBean”); OR

Spring Dependency Injection Inversion of Control (IoC) “Hollywood Principle” Don't call me, I'll call you “Container” resolves (injects) dependencies of components by setting implementation object (push) As opposed to component instantiating or Service Locator pattern where component locates implementation (pull) Martin Fowler calls Dependency Injection

Dependency Injection (cont'd) BeanFactory configured components need have no Spring dependencies Simple JavaBeans Beans are singletons by default Properties may be simple values or references to other beans Built-in support for defining Lists, Maps, Sets, and Properties collection types.

XmlBeanFactory Example Property and constructor based IoC 1 1

Bean Creation Direct instantiation BeanFactory instantiation Same syntax but class is subclass of BeanFactory getObject() called to obtain Bean Static Factory Instance Factory Method

Autowiring Properties Beans may be auto-wired (rather than using ) Per-bean attribute autowire Explicit settings override autowire=“name” Bean identifier matches property name autowire=“type” Type matches other defined bean autowire=”constructor” Match constructor argument types autowire=”autodetect” Attempt by constructor, otherwise “type”

Web Initialization Web applications may use ContextLoaderListener to initialize Spring contextConfigLocation /WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml org.springframework.web.context.ContextLoaderListener web.xml Automatically done by Spring DispatcherServlet

ApplicationContext Example <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> database.properties <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> ${database.connection.driver_class} ${database.connection.url}

Spring AOP

AOP Fundamentals Aspect-oriented programming (AOP) provides for simplified application of cross-cutting concerns Transaction management Security Logging Auditing Locking

Transactions

AOP Transactions Spring provides AOP support for declarative transactions Delegates to a PlatformTransactionManager instance DataSourceTransactionManager HibernateTransactionManager JdoTransactionManager JtaTransactionManager

Transaction Configuration <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"> com/../model/*.hbm.xml <bean id="transactionManager” class="org.springframework.orm.hibernate.HibernateTransactionManager">

Declarative Transactions Declarative transactional support can be added to any bean by using TransactionProxyFactoryBean Similar to EJB, transaction attributes may be defined on a per-method basis

Injecting Transaction Support <bean id=“reservationService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> PROPAGATION_REQUIRED PROPAGATION_REQUIRED,readOnly Declarative transaction support for single bean

Transaction Autoproxy < bean id="autoproxy" class="org...DefaultAdvisorAutoProxyCreator"> <bean id="transactionAdvisor" class="org...TransactionAttributeSourceAdvisor" autowire="constructor" > <bean id="transactionInterceptor" class="org...TransactionInterceptor" autowire="byType"> <bean id="transactionAttributeSource" class="org...AttributesTransactionAttributeSource" autowire="constructor"> <bean id="attributes" class="org...CommonsAttributes" /> Caches metadata from classes Generic autoproxy support Applies transaction using transactionManager Invokes interceptor based on attributes

Data Access

DAO support provides pluggable framework for persistence Currently supports JDBC, Hibernate, JDO, and iBatis Defines consistent exception hierarchy (based on RuntimeException) Provides abstract “Support” classes for each technology Template methods define specific queries

DAO Support The Data Access Object (DAO) support in Spring is primarily aimed at making it easy to work with data access technologies like JDBC, Hibernate or JDO in a standardized way.

DAO Support com.bt.bbv.r1oss

Hibernate DAO Example public class ReservationDaoImpl extends HibernateDaoSupport implements ReservationDao { public Reservation getReservation (Long orderId) { return (Reservation)getHibernateTemplate().load(Reservation.class, orderId); } public void saveReservation (Reservation r) { getHibernateTemplate().saveOrUpdate(r); } public void remove(Reservation Reservation) { getHibernateTemplate().delete(r); }

Hibernate DAO (cont’d) public Reservation[] findReservations(Room room) { List list = getHibernateTemplate().find( "from Reservation reservation “ + “ where reservation.resource =? “ + “ order by reservation.start", instrument); return (Reservation[]) list.toArray(new Reservation[list.size()]);

Hibernate DAO (cont’d) public Reservation[] findReservations(final DateRange range) { final HibernateTemplate template = getHibernateTemplate(); List list = (List) template.execute(new HibernateCallback() { public Object doInHibernate(Session session) { Query query = session.createQuery( "from Reservation r “ + “ where r.start > :rangeStart and r.start < :rangeEnd “); query.setDate("rangeStart", range.getStartDate() query.setDate("rangeEnd", range.getEndDate()) return query.list(); } }); return (Reservation[]) list.toArray(new Reservation[list.size()]); }

Hibernate Example com/jensenp/Reservation/Room.hbm.xml com/jensenp/Reservation/Reservation.hbm.xml com/jensenp/Reservation/Resource.hbm.xml ${hibernate.dialect} ${hibernate.hbm2ddl.auto} ${hibernate.show_sql} <bean id=“reservationDao" class="com.jensenp.Reservation.ReservationDaoImpl">

JDBC Support JDBCTemplate provides Translation of SQLExceptions to more meaningful Spring Runtime exceptions Integrates thread-specific transactions MappingSQLQuery simplifies mapping of ResultSets to Java objects

Web Framework

DispatcherServlet The DispatcherServlet is the Spring Front Controller Initializes WebApplicationContext Uses /WEB-INF/[servlet-name]- servlet.xml by default WebApplicationContext is bound into ServletContext

DispatcherServlet Configuration HandlerMapping Routing of requests to handlers HandlerAdapter Adapts to handler interface. Default utilizes Controllers HandlerExceptionResolver Maps exceptions to error pages Similar to standard Servlet, but more flexible ViewResolver Maps symbolic name to view

Dispatcher Servlet Configuration MultipartResolver Handling of file upload LocaleResolver Default uses HTTP accept header, cookie, or session

Controllers Controller interface defines one method ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse resp) throws Exception ModelAndView consists of a view identifier and a Map of model data

Controller Implementations CommandControllers bind parameters to data objects AbstractCommandController AbstractFormController SimpleFormController WizardFormController

Integration with Struts

Integration with Struts - CISP classpath:com/btexact/cisp/api/CispApiEJB.wsdl - com.bt.bbv.core.service.cisp.webservice.CispApiEJBPort CispApiEJB CispApiEJBPort com.btexact.cisp.api.CispApiEJBPort

Integration with LDAP <public class TraditionalPersonDaoImpl implements PersonDao { public List getAllPersonNames() { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/dc=example,dc=com"); DirContext ctx = new InitialDirContext(env); } catch (NamingException e) { throw new RuntimeException(e); }

Integration with EJB

References Spring’s homepage: “Introducing the Spring Framework” by Rod Johnson: “Inversion of control containers and dependency injection” by Martin Fowler: AOP Alliance: