1 / 14

Spring Framework Integration

Spring Framework Integration. Lance Berry CIS 764 Fall 2006. The Spring Model. ORM. Web. …. Spring Integration with Other Components. Spring Framework. AOP. AspectJ. BeanFactory. POJO. Hibernate. Interface. POJI. Struts. Aspect Oriented Programming (AOP). What is AOP?

gelsey
Télécharger la présentation

Spring Framework Integration

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Spring Framework Integration Lance Berry CIS 764 Fall 2006

  2. The Spring Model

  3. ORM Web ….. 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 Spring’s 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 MessageWriter{public 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.prefix=prefix;} public void setSuffix(String suffix){ this.suffix=suffix;} pointcut doWriting(): execution(* MessageWriter.writeMessage()); before() : doWriting(){ System.out.println(prefix);} after() : doWriting(){ Sytem.out.printlng(suffix):} } }

  10. AspectJ.XML <?xml version=“1.0” encoding=“UTF-8”?><!DOCTYPE beans PUBLIC “-//SPRING/DTD BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd”> <beans> <bean id=“aspect” class=“MessageWrapper” factory-method=“aspectOf”> <property name=“prefix”> <value>Ha Ha!</value> </property> <property name=“suffix”> <value>Ho Ho!</value> </property> </bean> </beans>

  11. Putting It All Together import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlAPplicationContext; 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

More Related