AROUT THIS BOOK After building an application with what you've learned from part 2,you may want to integrate it with oth er applications or services.In part you'learn how to do that. Chapter 10 explores how to expose your application objects as remote services. You'll also learn how to seamlessly access remote services as though they were any other object in your application.Remoting technologies explored will include RMI. Hessian/Burlap,SOAP-based web services,and Spring's own HttpInvoker. Chapter 11 revisits spring MVC.showing how to use it to expose your application data as RESTful resources.In addition,you'll learn how to develop REST clients with Spring's RestTemplate. Chapter 12 looks at using Spring to send and receive asynchronous messages with JMS.In addition to basic JMS operations with Spring,you'll also learn how to use the open source Lingo project to expose and consume asynchronous remote services over JMS. Chapter 13 will show you how to use Spring to schedule jobs,send emails,access JNDI-configured resources,and manage your application objects with JMX. Wrapping our exploration of Spring.chapter 14 will show you how to use Spring to schedule jobs,send emails,and access JNDI-configured resources. Code conventions There are many code examples throughout this book.These examples will always appear inao If there isa part of an example Iwant you topay extra attention to,it will appear in a bolded c ode fo ont.Any class name,method nan or XML fragment within the normal text of the book will appear in code font as well. Many of Spring's classes and packages have exceptionally long (but expressive) names.Because of this,line-continuation markers()may be included when necessary. Not all code examples in this book will be complete.Often I only show a method or two from a class to focus on a particular topic.Complete source code for the appli- cations found throughout the book can be downloaded from the publisher's websit at www.manning.com/SpringinActionThirdEdition. About the author Craig Walls is a software developer with more than 13 years of experience and is the coauthor of XDoclet in Action(Manning,2003)and two earlier editions of Spring in Action (Manning,2005 and 2007).He's a zealous promoter of the Spring Framework, speaking frequently at local user groups and conferences and writing about Spring on his blog.When he's not slinging code,Craig spends as much time as he can with his wife,two daughters,six birds,four dogs,two cats,and an ever-fluctuating number of tropical fish.Craig lives in Plano,Texas. Author Online Purchase of Spring in Action,Third Edition includes free access to a private web forum run by Manning Publications where you can make comments about the book,ask
ABOUT THIS BOOK xxi After building an application with what you’ve learned from part 2, you may want to integrate it with other applications or services. In part 3 you’ll learn how to do that. Chapter 10 explores how to expose your application objects as remote services. You’ll also learn how to seamlessly access remote services as though they were any other object in your application. Remoting technologies explored will include RMI, Hessian/Burlap, SOAP-based web services, and Spring’s own HttpInvoker. Chapter 11 revisits Spring MVC, showing how to use it to expose your application data as RESTful resources. In addition, you’ll learn how to develop REST clients with Spring’s RestTemplate. Chapter 12 looks at using Spring to send and receive asynchronous messages with JMS. In addition to basic JMS operations with Spring, you’ll also learn how to use the open source Lingo project to expose and consume asynchronous remote services over JMS. Chapter 13 will show you how to use Spring to schedule jobs, send emails, access JNDI-configured resources, and manage your application objects with JMX. Wrapping up our exploration of Spring, chapter 14 will show you how to use Spring to schedule jobs, send emails, and access JNDI-configured resources. Code conventions There are many code examples throughout this book. These examples will always appear in a fixed-width code font. If there is a part of an example I want you to pay extra attention to, it will appear in a bolded code font. Any class name, method name or XML fragment within the normal text of the book will appear in code font as well. Many of Spring’s classes and packages have exceptionally long (but expressive) names. Because of this, line-continuation markers (➥) may be included when necessary. Not all code examples in this book will be complete. Often I only show a method or two from a class to focus on a particular topic. Complete source code for the applications found throughout the book can be downloaded from the publisher’s website at www.manning.com/SpringinActionThirdEdition. About the author Craig Walls is a software developer with more than 13 years of experience and is the coauthor of XDoclet in Action (Manning, 2003) and two earlier editions of Spring in Action (Manning, 2005 and 2007). He’s a zealous promoter of the Spring Framework, speaking frequently at local user groups and conferences and writing about Spring on his blog. When he’s not slinging code, Craig spends as much time as he can with his wife, two daughters, six birds, four dogs, two cats, and an ever-fluctuating number of tropical fish. Craig lives in Plano, Texas. Author Online Purchase of Spring in Action, Third Edition includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask Licensed to Christian Cederquist <chrisman@kaus.dk>
ABOUT THIS BOOK technical questions,and receive help from the author and from other users.To access the forum and subscribe to it,point your web browser to www.manning.com/ SpringinActionThirdEdition.This page provides information on how to get on the forum once you are registered,what kind of help is available,and the rules of con duct on the forum. Manning's commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place.It is not a commitment to any specific amount of participation on the part of the author,whose contribution to the book's forum remains voluntary (and unpaid). We suggest you try asking the author some challenging questions,lest his interest stray! The Author Online forum and the archives of previous discussions will be accessi- ble from the publisher's website as long as the book is in print About the title By combining introductions,overviews,and how-to examples,the In Action books are designed to help learning and remembering.According to research in cognitive sci- ence,the things people remember are things they discover during self-motivated exploration Although no one at Manning is a cognitive scientist,we are convinced that for learning to become permanent it must pass through stages of exploration,play,and interestingly,retelling of what is being learned.People understand and remember new things,which is to say they master them,only after actively exploring them. Humans learn in action.An essential part of an In Action guide is that it is example driven.It encourages the reader to try things out,to play with new code,and explore new ideas. There is another,more mundane,reason for the title of this book:our readers are busy.They use books to do a job or to solve a problem.They need books that allow them to jump in and jump out easily and learn just what they want just when they want it.They need books that aid them in action.The books in this series are designed for such readers
xxii ABOUT THIS BOOK technical questions, and receive help from the author and from other users. To access the forum and subscribe to it, point your web browser to www.manning.com/ SpringinActionThirdEdition. This page provides information on how to get on the forum once you are registered, what kind of help is available, and the rules of conduct on the forum. Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It is not a commitment to any specific amount of participation on the part of the author, whose contribution to the book’s forum remains voluntary (and unpaid). We suggest you try asking the author some challenging questions, lest his interest stray! The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print. About the title By combining introductions, overviews, and how-to examples, the In Action books are designed to help learning and remembering. According to research in cognitive science, the things people remember are things they discover during self-motivated exploration. Although no one at Manning is a cognitive scientist, we are convinced that for learning to become permanent it must pass through stages of exploration, play, and, interestingly, retelling of what is being learned. People understand and remember new things, which is to say they master them, only after actively exploring them. Humans learn in action. An essential part of an In Action guide is that it is exampledriven. It encourages the reader to try things out, to play with new code, and explore new ideas. There is another, more mundane, reason for the title of this book: our readers are busy. They use books to do a job or to solve a problem. They need books that allow them to jump in and jump out easily and learn just what they want just when they want it. They need books that aid them in action. The books in this series are designed for such readers. Licensed to Christian Cederquist <chrisman@kaus.dk>
about the cover illustration The figure on the cover of Spring in Action,Third Edition,is a"Le Caraco,"or an inhab itant of the province of Karak in southwest Jordan.Its capital is the city of Al-Karak, which boasts an ancient hilltop castle with magnificent views of the Dead Sea and sur- rounding plains. The illustration is taken from a French travel book,Encyclopedie des Voyages by J.G. St.Sauveur,published in 1796.Travel for pleasure was a relatively new phenomenon at the time and travel guides such as this one were popular,introducing both the tour- ist as well as the armchair traveler to the inhabitants of other regions of France and abroad. The diversity of the drawings in the Encclopedie des Voyages speaks vividly of the uniqueness and individuality of the world's towns and provinces just 200 years ago. This was a time when the dress codes of two regions separated by a few dozen miles identified people uniquely as belonging to one or the other.The travel guide brings to life a sense of isolation and distance of that period and of every other historic period except our own hyperkinetic present Dress codes have changed since then and the diversity by region,so rich at the time,has faded away.It is now often hard to tell the inhabitant of one continent from another.Perhaps,trying to view it optimistically,we have traded a cultural and visual diversity for a more varied personal life.Or a more varied and interesting intellectual and technical life. We at Manning celebrate the inventiveness,the initiative,and the fun of the com puter business with book covers based on the rich diversity of regional life two centu- ries ago brought back to life by the pictures from this travel guide xxi进
xxiii about the cover illustration The figure on the cover of Spring in Action, Third Edition, is a “Le Caraco,” or an inhabitant of the province of Karak in southwest Jordan. Its capital is the city of Al-Karak, which boasts an ancient hilltop castle with magnificent views of the Dead Sea and surrounding plains. The illustration is taken from a French travel book, Encyclopédie des Voyages by J. G. St. Sauveur, published in 1796. Travel for pleasure was a relatively new phenomenon at the time and travel guides such as this one were popular, introducing both the tourist as well as the armchair traveler to the inhabitants of other regions of France and abroad. The diversity of the drawings in the Encyclopédie des Voyages speaks vividly of the uniqueness and individuality of the world’s towns and provinces just 200 years ago. This was a time when the dress codes of two regions separated by a few dozen miles identified people uniquely as belonging to one or the other. The travel guide brings to life a sense of isolation and distance of that period and of every other historic period except our own hyperkinetic present. Dress codes have changed since then and the diversity by region, so rich at the time, has faded away. It is now often hard to tell the inhabitant of one continent from another. Perhaps, trying to view it optimistically, we have traded a cultural and visual diversity for a more varied personal life. Or a more varied and interesting intellectual and technical life. We at Manning celebrate the inventiveness, the initiative, and the fun of the computer business with book covers based on the rich diversity of regional life two centuries ago brought back to life by the pictures from this travel guide. Licensed to Christian Cederquist <chrisman@kaus.dk>
Part 1 Core Spring S pring does a lot of things.But when you break it down to its core parts. Spring's primary features are dependency injection (DI)and aspect-oriented programming (AOP).Starting in chapter 1,"Springing into action,"I'll give you a quick overview of DI and AOP in Spring and see how they can help you decou- ple application objects. In chapter 2,"Wiring beans,"we'll dive deeper into how to use Spring's XML based configuration to keep application objects loosely coupled with depen dency injection.You'll learn how to define application objects and then wire them with their dependencies. XML isn't the only way that Spring can be configured.Picking up where the previous chapter left off,chapter 3."Minimizing XML configuration in Spring." explores some new features in Spring that make it possible to wire application objects with minimal or(in some cases,no)XML. Chapter 4,"Aspect-oriented Spring,"explores how to use Spring's AoP fea tures to decouple systemwide services(such as security and auditing)from the objects they service.This chapter sets the stage for cha apters 6 and 9,where you'll learn how to use Spring AOP to provide declarative transaction and security
Part 1 Core Spring Spring does a lot of things. But when you break it down to its core parts, Spring’s primary features are dependency injection (DI) and aspect-oriented programming (AOP). Starting in chapter 1, “Springing into action,” I’ll give you a quick overview of DI and AOP in Spring and see how they can help you decouple application objects. In chapter 2, “Wiring beans,” we’ll dive deeper into how to use Spring’s XMLbased configuration to keep application objects loosely coupled with dependency injection. You’ll learn how to define application objects and then wire them with their dependencies. XML isn’t the only way that Spring can be configured. Picking up where the previous chapter left off, chapter 3, “Minimizing XML configuration in Spring,” explores some new features in Spring that make it possible to wire application objects with minimal or (in some cases, no) XML. Chapter 4, “Aspect-oriented Spring,” explores how to use Spring’s AOP features to decouple systemwide services (such as security and auditing) from the objects they service. This chapter sets the stage for chapters 6 and 9, where you’ll learn how to use Spring AOP to provide declarative transaction and security. Licensed to Christian Cederquist <chrisman@kaus.dk>
Springing into action This chapter covers .Exploring Spring's core modules Decoupling application objects Managing cross-cutting concerns with AOP Spring's bean container It all started with a bean. In 1996,the Java programming language was still a young,exciting,up-and coming platform.Many developers flocked to the language because they'd seen how to create rich and dynamic web applications using applets.They soon learned that there was more to this strange new language than animated juggling cartoon characters.Unlike any language before it,Java made it possible to write complex applications made up of discrete parts.They came for the applets,but they stayed for the components In December of that year,Sun Microsystems published the JavaBeans 1.00-A spec- ification.JavaBeans definedasofware component model for Java.This specification defined a set of coding policies that enabled simple Java objects to be reusable and easily composed into more complex applications.Although JavaBeans were intended as a general-purpose means of defining reusable application components
3 Springing into action It all started with a bean. In 1996, the Java programming language was still a young, exciting, up-andcoming platform. Many developers flocked to the language because they’d seen how to create rich and dynamic web applications using applets. They soon learned that there was more to this strange new language than animated juggling cartoon characters. Unlike any language before it, Java made it possible to write complex applications made up of discrete parts. They came for the applets, but they stayed for the components. In December of that year, Sun Microsystems published the JavaBeans 1.00-A specification. JavaBeans defined a software component model for Java. This specification defined a set of coding policies that enabled simple Java objects to be reusable and easily composed into more complex applications. Although JavaBeans were intended as a general-purpose means of defining reusable application components, This chapter covers Exploring Spring’s core modules Decoupling application objects Managing cross-cutting concerns with AOP Spring’s bean container Licensed to Christian Cederquist <chrisman@kaus.dk>