Spring Framework Integration - PowerPoint PPT Presentation

About This Presentation
Title:

Spring Framework Integration

Description:

Spring Framework Integration Lance Berry CIS 764 Fall 2006 The Spring Model Spring Integration with Other Components Aspect Oriented Programming (AOP) What is AOP? – PowerPoint PPT presentation

Number of Views:742
Avg rating:3.0/5.0
Slides: 15
Provided by: Lance76
Category:

less

Transcript and Presenter's Notes

Title: Spring Framework Integration


1
Spring Framework Integration
  • Lance Berry CIS 764 Fall 2006

2
The Spring Model
3
Spring Integration with Other Components
Spring Framework
AOP
AspectJ
BeanFactory
POJO
Hibernate
Interface
POJI
Struts
4
Aspect Oriented Programming (AOP)
  • What is AOP?
  • AOP is an extension to Object-Oriented
    Programming.
  • Closely resembles Java Servlet Filters
  • AOP allows a developer to add testing or
    validation external to a class
  • Spring Supports both a native AOP and hooks into
    the AspectJ AOP Framework.

5
Aspect Oriented Programming Definitions and Terms
  • Aspect modularization of a concern across
    multiple objects (called Cross-Cut Concerns in
    AOP).
  • Advice Action taken by an Aspect
  • Joinpoint (called point cut in AOP) Point
    defined during execution.
  • Target (or advised object) Object being
    advised
  • AOP proxy Object created to implement Aspect
    contracts and the primary method used in Springs
    AOP implementation.
  • Weaving linking Aspects with other application
    types and objects.

6
Types of Advice
  • Before processing before method invocation.
    Good for security or preprocessing validation.
  • After -- processing after method invocation.
    Good for verification or checking processing
    method accuracy
  • Around Before and after method invocation.
    Good for checking changed values.
  • Throws After method invocation, but only if an
    exception was raised
  • Introduction special type of Advice that
    Introduces implementations to an object
    dynamically.

7
Example Spring AspectJ Using Before and After
Advice
8
MessageWriter Code
  • public class MessageWriterpublic void
    writeMessage()
  • System.out.println(foobar)
  • public void foo()
  • System.out.println(foo!)

9
MessageWrapper Code
  • public aspect MessageWrapper
  • private String prefix
  • private String suffix
  • public void setPrefix(String prefix)
  • this.prefixprefix
  • public void setSuffix(String suffix)
  • this.suffixsuffix
  • pointcut doWriting()
  • execution( MessageWriter.writeMessage())
  • before() doWriting()
  • System.out.println(prefix)
  • after() doWriting()
  • Sytem.out.printlng(suffix)

10
AspectJ.XML
  • lt?xml version1.0 encodingUTF-8?gtlt!DOCTYPE
    beans PUBLIC -//SPRING/DTD BEAN//EN
    http//www.springframework.org/dtd/spring-beans.d
    tdgt
  • ltbeansgt
  • ltbean idaspect
  • classMessageWrapper factory-methodaspectOf
    gt
  • ltproperty nameprefixgt
  • ltvaluegtHa Ha!lt/valuegt
  • lt/propertygt
  • ltproperty namesuffixgt
  • ltvaluegtHo Ho!lt/valuegt
  • lt/propertygt
  • lt/beangt
  • lt/beansgt

11
Putting It All Together
  • import org.springframework.context.ApplicationCont
    ext
  • import org.springframework.context.support.FileSys
    temXmlAPplicationContext
  • Public class AspectJExample
  • public static void main(String args)
  • Application context ctx new
    FileSystemXmlApplicationContext(AspectJ.xm)
  • MessageWriter writer new MessageWriter()
  • writer.writeMessage()
  • writer.foo()

12
The Output
  • Ha Ha!foobar!Ho Ho!foo

13
Hibernate Integration
14
The End
Write a Comment
User Comments (0)
About PowerShow.com