Spring 2.5 Aspect-Oriented Programming Create dynamic, feature-rich, and robust enterprise applications using the Spring framework Massimiliano Dessì BIRMINGHAM - MUMBAI This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801 Spring 2.5 Aspect-Oriented Programming Copyright © 2009 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: February 2009 Production Reference: 1170209 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-847194-02-2 www.packtpub.com Cover Image by Parag Kadam ([email protected]) This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801 Credits Author Project Manager Massimiliano Dessì Abhijeet Deobhakta Reviewer Project Coordinator Stefano Sanna Neelkanth Mehta Acquisition Editor Indexer Rashmi Phadnis Rekha Nair Development Editor Proofreader Dhiraj Chandiramani Chris Smith Technical Editor Production Coordinator Abhinav Prasoon Aparna Bhagat Copy Editor Cover Designer Sneha Kulkarni Aparna Bhagat Editorial Team Leader Akshara Aware This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801 About the Author Massimiliano Dessì iiss aann eexxppeerriieenncceedd ��aavvaa ddeevveellooppeerr wwhhoo ssttaarrtteedd ddeevveellooppiinngg ��EEEE applications in 2000. In 2004 he discovered the Spring Framework 1.0, and since then he has been one of its most enthusiastic users. Massimiliano is specialized in design and development of enterprise Web-based applications, such as portals, content management systems and banking applications. �EE technology and applied agile methodologies like eXtreme Programming are his core skills. He currently works as a Software Architect and Engineer for Sourcesense (www.sourcesense.com), one of the leading European Open Source System Integrators. He have a strong background as a community supporter and open- source software contributor. He's also an active technical writer, author of various articles, publications, and reviews availables on http://www.jugsardegna.org/ vqwiki/jsp/Wiki?MassimilianoDessi and on http://wiki.java.net/bin/ view/People/MassimilianoDessi. Massimiliano also speaks regurarly at Users Groups conferences (including �ava Users Groups, Spring Framework User Group, �avaday, and Linux Users Groups). He is one of the founders of �ava User Group Sardinia (http://www.jugsardegna. org), as well as the founder of "Spring Framework Italian User Group", "�etspeed Italian user Group" and "Groovy Italian User Group". He maintains a personal weblog at: http://jroller.com/page/desmax. Massimiliano lives in Cagliari, Sardinia with his family. This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801 About the Reviewer Stefano Sanna is senior engineer and �ava ME Tech Lead at Beeweeb Technologies (Rome), where his activities are focused on mobile multimedia applications (�ME, iPhone, Android). His experience on �ava for mobile devices began in 1999 on a Psion handheld computer. He is author of the Italian book "�ava Micro Edition", targeted on developing network-oriented applications for mobile phones and published by Hoepli (Nov 2007). He has written more than 50 technical articles on �ava ME, mobile technologies, and Linux. He has presented more than 30 seminars on the same topics, including Sun SPOTs and Arduino sensor networks. Stefano supports some Italian communities: �UG Sardegna, �ava Mobile Developers Forum, and �ava Italian Association. Before joining Beeweeb, he was a software engineer at CRS4 (Sardinia) in the Network Distributed Applications group, where he worked on multimodal applications and mobile cartography. He regularly writes about mobile computing, �ava, embedded systems, and good Italian food on his blog: http://www.gerdavax.it. This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801 This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801 This book is dedicated to my wife Monica and my children Michele, Mattia and Chiara This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801 This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801 Table of Contents Preface 1 Chapter 1: Understanding AOP Concepts 7 Limits of object-oriented programming 8 Code scattering 13 Code tangling 14 The AOP solution 16 What Spring provides in terms of AOP 19 Programmatic way 20 Before advice 20 After returning advice 21 Around advice 23 After throwing advice 24 The old Spring XML way 26 AOP with IoC in Spring 2.5 28 AspectJ annotations 28 Before advice 29 After returning advice 30 Around advice 31 After (finally) advice 32 After throwing advice 33 Schema-based configuration 35 Before advice 35 After advice 36 After returning advice 37 After throwing advice 37 Around advice 39 Summary 40 Chapter 2: Spring AOP Components 41 Aspect 41 Pointcut 41 This material is copyright and is licensed for the sole use by Richard Ostheimer on 6th June 2009 2205 hilda ave., , missoula, , 59801
Description: