Thank you for visiting us. We are currently updating our shopping cart and regret to advise that it will be unavailable until September 1, 2014. We apologise for any inconvenience and look forward to serving you again.

Wiley
Wiley.com
Print this page Share

Beginning Spring Framework 2

ISBN: 978-0-470-10161-2
472 pages
December 2007
Beginning Spring Framework 2 (047010161X) cover image
Beginning Spring Framework 2 shows beginning Java developers how to build serverside Java applications using the latest 2.0 release of the Spring Framework. The book does not assume any previous knowledge of J2EE--in fact, the authors argue that beginners learn more quickly by starting directly with Spring.

The authors show readers how to build a working web application using Spring with other open source tools and technologies, all of which can be freely downloaded and installed via the Internet. Each chapter builds a portion of the application. All the Spring concepts and construction techniques are introduced during the design and coding of this application. (With minor adaptation, the resulting code can be re-used by readers in their own working applications.)

See More

Acknowledgments x

Introduction xix

Chapter 1: Jump Start Spring 2 1

All About Spring 2

Focus on Simplicity 2

Applying Spring 2

Creating a Modularized Application 3

Using Spring to Configure a Modularized Application 8

Wiring Beans Automatically by Type 14

Understanding Spring’s Inversion of Control (IoC) Container 16

Adding Aspect-Oriented Programming to the Mix 20

Adding a Logging Aspect 21

Beyond Plumbing — Spring API Libraries 25

Using Spring APIs To Facilitate Application Creation 26

Summary 27

Chapter 2: Designing Spring Applications 29

Overview of the PIX Album-Management System 30

The PIX System Requirements 31

Discovering the Domain Model 33

The PixUser POJO 33

The Affiliate POJO 35

The Picture Object 36

The Album POJO 37

The Comment POJO 38

The POJO Relationships 39

The Importance of Unit Testing 45

POJO-Based Design and Containerless Unit Testing 46

Regression Testing 46

Working with a Unit-Testing Framework 47

Summary 52

Chapter 3: Spring Persistence Using JPA 53

Java Persistence 54

JDBC Architecture 54

Traditional JDBC Approach 56

DAO — Unifying Data Access 64

Spring DAO Support 64

Spring Exception Translation 73

Spring and JPA 74

Entities 74

Spring as a JPA Container 81

About JPA APIs 81

JPA the Easy Way — Using Annotations 81

SPRING JPA Exception Translation 82

SPRING JPA DAOs 83

Spring JPA Configuration 84

Persistence and the PIX Domain Model 87

Persisting The PixUser POJO 87

Implementing PixUser Repository DAO 89

Implementing the Album Repository DAO 90

Testing the Persistence Layer 91

Spring Test Support 92

Executing the Persistence Test Suite 92

Testing the PIX Repositories 92

Summary 93

Chapter 4: Using Spring MVC to Build Web Pages 95

The MVC Architectural Pattern 95

The Sample Application’s Architecture 96

Spring MVC Development 99

Processing Web Requests with Controllers 99

Presenting the Model with a View 105

Getting Data from the User with Forms 109

A Basic Form-Submission Workflow 109

Using the Form View 112

When Things Go Wrong 123

Summary 124

Chapter 5: Advanced Spring MVC 125

Submitting a Form Across Multiple Pages 126

Adding Pictures to an Album 126

Developing Wizard Form Pages 127

Implementing Wizard Form Actions 131

Validating Data Submitted Through a Wizard 132

Uploading Files 133

Getting More Stuff Done with the Same Controller 134

Creating a Different View 137

Your First View 138

Saving an Album to PDF 139

Generating an RSS Feed 142

Personalization 146

Retrieving Text Labels from a Message Source 146

Displaying Application Labels in a Different Language 148

Changing the Application’s Language Settings 150

Allowing the User to Personalize the Application 151

Summary 154

Chapter 6: Spring Web Flow 155

Examining a Sample Work Flow for Loan Applications 156

Introducing Spring Web Flow 157

How SWF Works with Spring MVC 158

Launching Flows 159

Implementing SWF in the PixWeb Application 161

The Login Flow 161

The Album Creation Flow 176

Implementing Actions 178

Implementing Views 181

Testing Flows 183

Architectural Overview 185

Advanced Topics 186

REST-Style URLs 187

Flow Execution Repositories 188

Flow Execution Repository Implementations 189

Subflows and Attribute Mappers 189

Flow Execution Listeners 189

Exception Handlers 190

Summary 190

Chapter 7: Ajax and Spring: Direct Web Remoting Integration 191

Web 2.0: The World of Ajax 192

Ajax Basics 192

Client-Side Ajax Development with JavaScript 194

The XMLHttpRequest Object 194

Introducing Direct Web Remoting 2 199

Downloading DWR 2 201

Working with DWR 2 202

Integrating Spring and DWR 2 210

Summary 229

Chapter 8: Spring and JMS — Message-Driven POJOs 231

JMS Concepts 232

JMS Messaging Domains 232

Point-To-Point Messaging 232

Publish/Subscribe Messaging 233

Persistence versus Durability 234

The JMS Message 234

Message Header 234

Message Properties 235

Message Selectors 235

Message Body 235

Producing JMS Messages 236

Consuming JMS Messages 236

Synchronous Message Consumption 236

Asynchronous Message Consumption 237

The Spring JMS Framework 238

The Spring JMS Packages 238

The JmsTemplate Class 239

Message Listener Containers 240

Destinations 241

Transactions 241

Configuring Message-Driven POJOS 241

Realizing the JMS Use Case 242

Modeling Message-Driven POJOs 242

The PIX Web POJOS 242

Changing the PIX Web POJOs Into Message-Driven POJOs 245

A JMS Provider — Apache ActiveMQ 247

The JMS Template in the PIX Web Application 253

Summary 256

Chapter 9: Spring Web Services and Remoting 259

Web Service Benefits 260

Introducing Web Services 260

Web Services Architecture 261

The Network Layer 261

XML 261

SOAP 262

WSDL 262

UDDI 264

Web Services Interactions 265

Web Services Interoperability 266

Java Web Service Technologies 266

Java Web Application Web Services 266

Spring Remoting 268

SOAP Frameworks 268

Java-to-XML Bindings 269

XFire 269

Spring Web Services with XFire 270

Realizing the PIX AffiliateManagement Use Case 270

Invoking Web Services 277

SOAP Handlers 278

Testing SOAP Handlers with XFire 278

Summary 284

Chapter 10: Web Service Consumer and Interoperation with .NET 285

Creating Web Service Consumers — Overview 286

Describing Web Services with WSDL 286

Creating a Web Service Consumer with XFire 287

The XFire Maven Plugin 287

Invoking Web Service Methods via XFire-Generated Stubs 287

Understanding the E-Mail-Validation Web Service Consumer in PIX 288

Examining a WSDL Document 290

WSDL Description of a Web Service Endpoint 291

Generating Web Service Stubs from WSDL Using XFire 292

The XFire WsGen Tool 294

Generated Interface for Invocation of Web Service 295

Creating a Web Service Consumer with XFire-Generated Stubs 295

Add a Web Service Consumer to PIX 300

Web Service Interoperability 304

WS-I and Web Service Interoperability 304

Expose PIX Service for .NET Web Service Consumers 304

Summary 313

Chapter 11: Rapid Spring Development with Spring IDE 315

Brief Feature Overview 316

Installing and Setting Up Your Eclipse Environment 317

Installing Spring IDE 317

Preparing an Eclipse Project 319

Support for Spring Beans Configuration Files 325

Viewing Spring Bean Definitions 325

Validating Spring Bean Definition Files 328

XML Editing 332

Searching for and Navigating to Bean Definitions 335

Visual Support for Spring AOP Configurations 337

Enabling AOP Support for Spring Projects 338

Working with Spring IDE’s AOP Support 339

Integration with the AspectJ Development Tools 343

Web Flow Development with Spring IDE 344

Setting Up Your Spring Web Flow Project 344

Validating Spring Web Flow Definition Files 348

Editing Spring Web Flow Definition Files 350

Graphical Editor for Web Flow Definitions 351

Summary 353

Chapter 12: Spring AOP and AspectJ 355

Comparing Aspect-Oriented Programming to Object-Oriented Programming 355

What Is AOP? 357

Crosscutting Concerns 357

AOP in Spring 361

XML Schema-Based Support 362

The AOP Namespace Explored 362

Advice Parameters 367

AspectJ Support 368

@AspectJ Explored 368

@AspectJ-Style Advice 372

Performance Monitoring with AOP and JETM 376

Summary 379

References 380

Chapter 13: More AOP: Transactions 381

Understanding Transactions 382

Understanding Spring Transaction Management 383

Spring Transaction Abstraction 384

Applying AOP to Transactions 387

Adding Spring Transaction Support to PIX 38

Selecting the Transaction Manager 389

Coding Spring Transactions 397

Global Transactions 405

Summary 406

Appendix A: Maven 2 Basics 407

Appendix B: Spring and Java EE 439

Appendix C: Getting Ready for the Code Examples 451

Index 453

See More
Thomas Van de Velde has extensive experience developing high-traffic public-facing web sites across a wide range of industries. As a consultant and project manager for one of the leading global technology consulting firms, he has worked on delivering the French online tax declaration and one of the United States’ largest sports sites. Thomas is passionate about finding ways to leverage open source in the enterprise, and in his free time tries to catch a wave in southern California where he lives with his wife and daughter.

Bruce Snyder is a veteran of enterprise software development and a recognized leader in open-source software. Bruce has experience in a wide range of technologies including Java EE, messaging, and serviceoriented architecture. In addition to his role as a principal engineer for IONA Technologies, Bruce is also a founding member of Apache Geronimo and a developer for Apache ActiveMQ, Apache ServiceMix, and Castor, among other things. Bruce serves as a member of various JCP expert groups and is the co-author of Professional Apache Geronimo from Wrox Press. Bruce is also a frequent speaker at industry conferences, including the Colorado Software Summit, TheServerSide Java Symposium, Java in Action, JavaOne, ApacheCon, JAOO, SOA Web Services Edge, No Fluff Just Stuff, and various Java users groups. Bruce lives in beautiful Boulder, Colorado with his family.

Christian Dupuis is working for one of the world’s leading consulting companies and is a member of the Technical Architecture capability group. Christian has been working as a technical architect and implementation lead to design and implement multi-channel, mission-critical financial applications that leverage Spring and other open-source frameworks across all tiers. Christian is co-lead of the Spring IDE open-source project (http://springide.org), providing tool support for the Spring Portfolio.

Sing Li (who was bitten by the microcomputer bug in the late 1970s) has grown up in the Microprocessor Age. His first personal computer was a $99 do-it-yourself Netronics COSMIC ELF computer with 256 bytes of memory, mail-ordered from the back pages of Popular Electronics magazine. A 25-year industry veteran, Sing is a system developer, open-source software contributor, and freelance writer specializing in Java technology and embedded and distributed systems architecture. He regularly writes for several popular technical journals and e-zines, and is the creator of the Internet Global Phone, one of the very first Internet phones available. He has authored and co-authored a number of books across diverse technical disciplines including Geronimo, Tomcat, JSP, servlets, XML, Jini, media streaming, device drivers, and JXTA.

Anne Horton has worked in the software industry for 24 years as a software engineer, textbook technical editor, author, and Java architect. She currently works for Lockheed Martin and spends her weekends working with Sing Li (author) and Sydney Jones (editor) in developing bleeding-edge books such as this one. You can email her at abhorton@comcast.net.

Naveen Balani works as an architect with IBM India Software Labs (ISL). He leads the design and development activities for the WebSphere Business Service Fabric product out of ISL. He likes to research upcoming technologies and is a regular contributor to IBM developer works covering such topics as web services, ESB, JMS, SOA, architectures, open-source frameworks, semantic web, J2ME, persuasive computing, the Spring series, AJAX, and various IBM products. You can e-mail him at naveenbalani@rediffmail.com.

See More
Download TitleSizeDownload
All code downloads / samples from the book
Updated 9/18/09
1.19 MB Click to Download
See More

Do you think you've discovered an error in this book? Please check the list of errata below to see if we've already addressed the error. If not, please submit the error via our Errata Form. We will attempt to verify your error; if you're right, we will post a correction below.

ChapterPageDetailsDatePrint Run
47 Error in Directory
"Trying it Out -- Creating Unit Test Cases"
bullet item 1. says,
wrox-pix-web\test\java\com\wrox\beginspring\pix\model directory
Should be:
wrox-pix-web\src\test\java\com\wrox\beginspring\pix\model
03/13/08
61 Error in Text
In Step 3 on Page 61, the following text should be added:

If you look under wrox-pix-web/src/test/resources, you will find a file named pixhsql.sql This file is an SQL command file. Load it into a text editor to view if you are curious. It basically contains the SQL commands to create the required tables.

You should first run the following command to create the tables:

java -cp ./target/pixweb-0.0.1/WEB-INF/lib/hsqldb-1.8.0.7.jar org.hsqldb.util.SqlTool pix-sa src/test/resources/pixhsql.sql

The output you will see is:

1 row updated
1 row updated

The above must be executed before using the following command as detailed in Step 3 on Page 61:

java -cp ./target/pixweb-0.0.1/WEB-INF/lib/hsqldb-1.8.0.7.jar org.hsqldb.util.SqlTool pix-sa
9/17/09
62 Error in Text
On Page 62, Step 4, the command to execute the AlbumDaoTest needs to be modified slightly:

mvn exec:java -Dexec.classpathScope=test -Dexec.mainClass=com.wrox.beginspring.pix.dao.examples.AlbumDaoTest

The additional -Dexec.classpathScope=test tells Maven to include the default test classpath when looking for Java classes to execute.
9/17/09
See More

Related Titles

Back to Top