By Ru Shen Department of Computer Science UAlbany, 2008

Slides:



Advertisements
Similar presentations
Introduction to the Spring Framework
Advertisements

Apache Struts Technology
Aspect Oriented Programming. AOP Contents 1 Overview 2 Terminology 3 The Problem 4 The Solution 4 Join point models 5 Implementation 6 Terminology Review.
1 JAC : Aspect Oriented Programming in Java An article review by Yuval Nir and Limor Lahiani.
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.
The Spring Framework: A brief introduction to Inversion of Control James Brundege
Intro to Spring CJUG - January What is Spring? “The Spring framework provides central transaction control of various objects.” This means that any.
Using Third-Party Frameworks in Building Blocks™ David Ashman Principal Architect, Product Development.
Struts 2.0 an Overview ( )
UNIT-V The MVC architecture and Struts 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.
The Spring Framework Training Get to know Spring Framework Rohit Prabhakar
Aspect Oriented Programming (AOP) in.NET Brent Krueger 12/20/13.
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
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.
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.
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
Spring Training 17/09/ Dependency Injection.
Introduction to Web Dimitar Nenchev Ivan Nakov
A Presentation By V AIBHAV S AHARAN Web-enHanced Information Management COMS E6125.
AOP-1 Aspect Oriented Programming. AOP-2 Aspects of AOP and Related Tools Limitation of OO Separation of Concerns Aspect Oriented programming AspectJ.
Spring Framework. About spring Spring is the most popular application development framework for enterprise Java. Millions of developers around the world.
Chapter 8: Aspect Oriented Programming Omar Meqdadi SE 3860 Lecture 8 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions Buenos Aires, June 2009.
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.
Aspect Oriented Programming Adlux Consultancy Services Pvt Ltd
Kansas City Java User’s Group Jason W. Bedell July 12, 2006
问题 Code scattering Blocks of duplicated code Blocks of complementary code, and different modules implementing complementary parts of the concern Code.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Introduction to Yan Cui Aspect Oriented Programming by
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.
Singleton Academy, Pune. Course syllabus Singleton Academy Pune – Course Syllabus1.
L’origine dei mali: le dipendenze tra componenti Stefano Leli 14° Workshop DotNetMarche Venerdì 16 aprile
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions and Spring MVC Buenos Aires, June 2009.
Google Code Libraries Dima Ionut Daniel. Contents What is Google Code? LDAPBeans Object-ldap-mapping Ldap-ODM Bug4j jOOR Rapa jongo Conclusion Bibliography.
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 Lecture 6: Spring – IoC and Dependency Injection
Structure of a web application
Chengyu Sun California State University, Los Angeles
Introduction to J2EE Architecture
Intro to Spring CJUG - January 2013.
J2EE Application Development
Chengyu Sun California State University, Los Angeles
Objectives In this lesson, you will learn to:
Introduction to Spring Framework and Dependency Injection
JAsCo an Aspect-Oriented approach tailored for
An Introduction to Software Architecture
Developing and testing enterprise Java applications
CS520 Web Programming Spring – Aspect Oriented Programming
Enterprise Java Beans.
Leveraging ColdSpring To Make Better Applications
Aspect Oriented Programming
Presentation transcript:

By Ru Shen Department of Computer Science UAlbany, 2008 Spring Framework By Ru Shen Department of Computer Science UAlbany, 2008

Outline of the presentation History of Spring The framework What is it good for? Spring Inversion of Control Spring Aspect Oriented Programming My experience with Spring AOP Installing Spring References Small assignment

A little bit of history Who Rod Johnson (Sydney University) When Spring was started in Feb 2003. What Spring is an open source framework for building enterprise Java applications.

Overview of Spring framework Picture excerpted from Manning – Spring in Action by Craig Walls and Ryan Breidenbach

Overview of Spring framework continued The core container is the fundamental layer of the framework that provides Inversion of Control functionality. Application context module extends the core modules by supplying many enterprise services such as JNDI access, remote access, multi-language support and scheduling. AOP module provides rich support for aspect-oriented programming.

Overview of framework contintued JDBC layer simplifies the process of database connection. ORM module provides compatibility to existing framework such as Hibernate, JDO and TopLink. Web module provides a context for web-based applications. Spring comes with a full-featured MVC framework for building web applications.

What is Spring good for? Allows you to build applications with Plain Old Java Objects (POJOs) containing only the business logic. vs EJB The famous “Inversion of Control”. Compatible with various ORM technology, such as TopLink and Hibernate. Provides a testing framework that you can perform unit testing on. Supports Aspect Oriented Programming. Supports Model-View-Controller framework.

Spring IoC IoC stands for Inversion of Control Hollywood Principle: “Don’t call me, I’ll call you.” In a nutshell … inversion of control is about: the responsibility of coordinating collaboration between dependent objects is transferred away from the objects themselves. – Spring in Action

Traditional approach In order to use object B, object A has to instantiate from Class B. In order to use object C, object B has to instantiate from Class C. Object A Object B Class B Object C Class C

Problem with traditional approach Classes are tightly coupled Hard to test: A← B, B← C Hard to reuse Hard to understand: cannot see the main flow Hard to maintain: fixing one bug may result creating more new bugs Utilizing interface will not solve the problem

Revised approach changes … <beans> <bean id=A class=A> <property name=b> <ref bean=B> </property> </bean> <bean id=B class=B> <property name=c> <ref bean=C> <bean id=C class=C/> </beans> Class A{ private BGroup b; … Public void setBGroup(BGroup b){ this.b = b; } Interface BGroup Class B{ private CGroup c; … Public void setCGroup(CGroup c){ this.c = c; } Class B’ Class B’’ Interface CGroup Class C Class C’ Class C’’

Components of Spring IoC IoC is practiced using Dependency Injection Two forms of DI: Setter Injection and Constructor Injection Code are decoupled with interface Spring IoC Container is the platform Bean factory produce beans Configuration file defines beans and the main flow

Demonstrate Spring IoC Bean factory is created with a single line of code Beans are obtained from the bean factory Picture excerpted from Manning – Spring in Action by Craig Walls and Ryan Breidenbach

Demonstrate Spring IoC continued Picture excerpted from Manning – Spring in Action by Craig Walls and Ryan Breidenbach

Demonstrate Spring IoC continued Things to notice: Class implements interface A setter method Container calls the setter What’s the impact: Any class that implements “Knight” can be called at run time Knight is GIVEN a quest rather than GETTING a quest Picture excerpted from Manning – Spring in Action by Craig Walls and Ryan Breidenbach

Demonstrate Spring IoC continued An example of Constructor Injection Picture excerpted from Manning – Spring in Action by Craig Walls and Ryan Breidenbach

Summarize Spring IoC Decoupling with interface Configuration file defines the rules Objects are given rather than obtained More options in the configuration file Inheritance between the beans Singleton or non-singleton Abstract beans The Spring container glues everything together

Spring AOP Aspect-Oriented Programming AOP complements OOP Decompose programs into aspects (concerns) An aspect crosscuts multiple programs Common aspects: Exception handling Transaction management Logging Security checking

Aspect-Oriented Programming Class A Class B Class C Aspect 1 (logging) Aspect 2 (security check) Classes handle functional requirements Use cases Functions Aspects handle non-functional requirements Security Logging One aspect usually impacts multiple classes. It’s tedious to implement the aspect in each class.

AOP concepts Aspect Join point – A method invocation Advice – Action to take at a join point Point cut – A set of join points Target – Object containing the join point AOP proxy and advisor – Objects for weaving the above components together

Type of Advices in AOP Before advice After advice Around advice Executed before a joint point. After advice Executed after a joint point completes. Around advice Most powerful one. Both before and after. Throws advice Before throwing an exception After throwing an exception

Weave the components together Advice Point cut Advisor + = + A method of Target = Deploy it to the Spring container! Proxy

My experience with Spring AOP The purpose: exception handling Background: Java Enterprise Application on EJB Backend Weblogic server Front end Swing Uniformed method for exception handling – prompt the formatted error messages to users

AOP continued … Vehicle management Driver management Add vehicle / driver Remove vehicle / driver Update vehicle / driver Search vehicle / driver Management module Vehicle management … Driver management … Scheduling module Dispatch module Report module

AOP continued Without using AOP, each exception has to be handled individually, even though they are handled in the same way. With AOP, we don’t handle exceptions in individual classes. We just throw them. One advice is sufficient to handle a group of exceptions.

AOP continued Spring embedded AOP objects ThrowsAdvice RegexpMethodPointcutAdvisor ProxyFactoryBean MyVehicleProxy ThrowsAdvice Pointcut Regular expression pattern Vehicle management bean MyAdvice ProxyFactoryBean RegexpMethodPointcutAdvisor MyAdvisor

Summarize Spring AOP Embedded objects to facilitate AOP implementation, runtime Works for Spring beans only – vehicle management bean has to be deployed in the container More things to explore with beforeAdvice, afterAdvice and aroundAdvice

Install Spring 1. Download Spring framework from http://www.springframework.org/download 2. Include the downloaded spring.jar in your $CLASSPATH. Maybe you need to download apache commons logging package: commons-logging-1.1.jar. It is used internally by Spring. 3. Write your first configuration file. 4. Create bean factory by specifying the location of the configuration file. 5. Refer each class through their bean name 6. Start writing your Java classes.

Reference Introduction by Rod Johnson on The Server Side http://www.theserverside.com/tt/articles/content/SpringFramework/article.html Manning – Spring in Action Spring reference documentation http://www.springframework.org/documentation

A small assignment Using Spring, write a simple program that prints the configuration of different brands of cars. Define Car as an interface. Try printing the configuration of different brands of cars by writing different implementation of Car. Modify the configuration file at runtime to switch between the cars every time and see the output.