Beginning Spring - Mert Caliskan - E-Book

Beginning Spring E-Book

Mert Caliskan

0,0
28,99 €

oder
-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Get up to speed quickly with this comprehensive guide to Spring Beginning Spring is the complete beginner's guide to Java's most popular framework. Written with an eye toward real-world enterprises, the book covers all aspects of application development within the Spring Framework. Extensive samples within each chapter allow developers to get up to speed quickly by providing concrete references for experimentation, building a skillset that drives successful application development by exploiting the full capabilities of Java's latest advances. Spring provides the exact toolset required to build an enterprise application, and has become the standard within the field. This book covers Spring 4.0, which contains support for Java 8 and Java EE 7. Readers begin with the basics of the framework, then go on to master the most commonly used tools and fundamental concepts inherent in any Spring project. The book emphasizes practicality and real-world application by addressing needs such as meeting customer demand and boosting productivity, and by providing actionable information that helps developers get the most out of the framework. Topics include: * Dependency Injection and Inversion of Control * Unit testing Spring enabled Web Applications * Data Access using Spring JDBC and ORM support along with Transaction Management * Building Web Applications and RESTful Web Services with Spring MVC * Securing Web Applications using Spring Security * Spring Expression Language with its Extensive Features * Aspect Oriented Programming Facilities Provided by Spring AOP * Caching with 3rd Party Cache Providers' Support * The Best of the Breed: Spring 4.0 The information is organized and structured an ideal way for students and corporate training programs, and explanations about inner workings of the framework make it a handy desk reference even for experienced developers. For novices, Beginning Spring is invaluable as a comprehensive guide to the real-world functionality of Spring.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 636

Veröffentlichungsjahr: 2015

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



CONTENTS

Foreword

Foreword

Introduction

Who This Book Is For

What This Book Covers

What You Need to Run the Samples

Conventions

Errata

p2p.wrox.com

Chapter 1: POJO Programming Model, Lightweight Containers, and Inversion of Control

POJO Programming Model

Lightweight Containers and Inversion of Control (IoC)

Dependency Injection

Summary

Chapter 2: Dependency Injection with Spring

Spring IoC Container

Dependency Injection

Spring-Managed Beans

Summary

Chapter 3: Building Web Applications Using Spring MVC

Learning the Features and Benefits of Spring MVC

Using the Dispatcher Servlet mechanism

Creating Your First Spring MVC Application

Configuring Spring MVC with Annotations

Handling Forms with JSP

Exploiting the Power of Annotations

Validating User Input

Uploading Files

Handling Exceptions

Implementing Internationalization (i18n)

Using Themes

Summary

Chapter 4: JDBC Data Access with Spring

Problems with Using Vanilla JDBC

Introducing Spring's JDBC Support

Performing Data Access Operations with Spring

Modeling JDBC Operations as Java Objects

Exception Handling and Error Code Translation

Summary

Chapter 5: Data Access with JPA Using Spring

Brief Introduction to ORM and JPA

Spring's JPA Support

Summary

Chapter 6: Managing Transactions with Spring

Understanding Transaction Management

Spring's Transaction Abstraction Model

Declarative Transaction Management with Spring

Programmatic Transaction Management with Spring

Executing Custom Logic Before or After Transactions

Summary

Chapter 7: Test-Driven Development with Spring

Configuring and Caching ApplicationContext

Injecting Dependencies of Test Fixtures

Using Transaction Management in Tests

Testing Web Applications

Using Mock Objects and Other Utilities for Testing

Summary

Chapter 8: Aspect-Oriented Programming with Spring

Getting Started with AOP in Spring

Becoming Familiar with Types of Advices

Defining Point-Cut Designators

Capitalizing on the Power of Annotations

Blending AspectJ with Spring

Configuring Spring AOP with Annotations

Summary

Chapter 9: Spring Expression Language

Configuring Applications with SpEL

Creating a Parser

Invoking Methods

Working with Variables and Functions

Understanding SpEL Operators

Using Utilities in SpEL

Summary

Chapter 10: Caching

Building Your First Caching Application

Working with Cache Annotations

Implementing Cache Managers

Casting Your SpEL on Caches

Initializing Your Caches Programmatically

Finding Alternative Cache Providers

Summary

Chapter 11: RESTful Web Services with Spring

Creating Your First REST Web Service

Returning Different HTTP Status Codes from REST Web Service

Learning an Annotation-Based Configuration Alternative

Using REST Web Services with XML

Using the Exception Handling Mechanism

Unit Testing RESTful Services

Summary

Chapter 12: Securing Web Applications with Spring Security

Why Spring Security?

Features of Spring Security

Configuring and Using Spring Security

Understanding the Fundamental Building Blocks of Spring Security

Authenticating Users

Authorizing Web Requests and Service Method Calls

Summary

Chapter 13: Next Stop: Spring 4.0

Keeping Up with the Latest: Java 8 and Java EE7 Support

Configuring Injection with Conditional Dependency

Ordering the Elements of Autowired Collections

Repeating Annotations

Introducing New Annotations

Summary

Appendix: Solutions to Exercises

Chapter 1

Chapter 2

Chapter 3

Chapter 4

Chapter 5

Chapter 6

Chapter 7

Chapter 8

Chapter 9

Chapter 10

Chapter 11

Chapter 12

Chapter 13

Index

End User License Agreement

List of Tables

Chapter 2

Table 2.1

Chapter 3

Table 3.1

Chapter 5

Table 5.1

Chapter 6

Table 6.1

Table 6.2

Chapter 8

Table 8.1

Table 8.2

Chapter 9

Table 9.1

Chapter 10

Table 10.1

Chapter 11

Table 11.1

Table 11.2

Chapter 12

Table 12.1

List of Illustrations

Chapter 1

Figure 1.1

Figure 1.2

Figure 1.3

Chapter 2

Figure 2.1

Figure 2.2

Figure 2.3

Figure 2.4

Chapter 3

Figure 3.1

Figure 3.2

Figure 3.3

Figure 3.4

Figure 3.5

Figure 3.6

Figure 3.7

Chapter 5

Figure 5.1

Chapter 6

Figure 6.1

Figure 6.2

Figure 6.3

Figure 6.4

Chapter 8

Figure 8.1

Figure 8.2

Figure 8.3

Chapter 11

Figure 11.1

Figure 11.2

Figure 11.3

Figure 11.4

Figure 11.5

Figure 11.6

Figure 11.7

Figure 11.8

Figure 11.9

Figure 11.10

Figure 11.11

Figure 11.12

Chapter 12

Figure 12.1

Figure 12.2

Figure 12.3

Figure 12.4

Figure 12.5

Figure 12.6

Figure 12.7

Figure 12.8

Guide

Cover

Table of Contents

1

Pages

xxvii

xxix

xxx

xxxi

xxxii

xxxiii

xxxiv

xxxv

xxxvi

xxxvii

xxxviii

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

135

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

237

238

239

240

241

242

243

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

312

313

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

331

332

333

334

335

336

337

338

339

340

341

342

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

FOREWORD

I have fond memories of Wrox books. The Spring story started 12 years ago from a Wrox book. Before that, I'd contributed chapters to several Wrox books and served as a reviewer on many others.

Some of these memories concern what the imprint has meant to me, but many relate to its philosophy and format, a key reason I was excited to become a Wrox author in 2000. The distinctive format offers an effective structure for imparting knowledge, encouraging the author to highlight important points, and promoting systematic explanation. It emphasizes practical code examples—the most valuable tool for teaching programming.

These virtues are evident in Mert Calıskan's and Kenan Sevindik's Beginning Spring. It's well structured, with plentiful examples that include clear instructions on getting the code running and step-by-step explanations.

Spring—like building enterprise Java applications itself—is a broad subject, making it impossible for an introductory book to cover even the core Spring Framework exhaustively. Mert and Kenan have done a good job in selecting what to focus on. The scope of this book is well chosen to get you productive as a Spring web developer: the core Dependency Injection container; the MVC framework (with a special emphasis on REST); relational data access and transaction management; the use of AOP and Spring EL to customize application behavior; and how Spring 4.0 embraces the important language enhancements in Java 8. Although Spring Security is the only Spring subproject covered, this book provides a solid base on which to build knowledge of the broad Spring ecosystem.

The level of the content is equally well targeted. There's a judicious mix of important background information (for example, the ACID properties of transactions) and specific detail about how to use Spring to get things done. Although this book assumes no knowledge of Spring, it does not waste time covering programming topics better served in more introductory books.

Although I'm no longer personally involved, I continue to observe Spring's progress with pleasure. Reading this book serves as a reminder of why Spring remains so relevant. The core concepts have stood up well over the past 12 years: for example, the consistent, lightweight approach to transaction management and the central principle of Dependency Injection. When you understand the “Spring way,” you can master additional Spring technologies quickly.

If you're a Java web developer as yet unfamiliar with Spring, you will find that Spring can make your life much easier, and I recommend this book as a good way to get started with it.

—ROD JOHNSON

FOREWORD

The Java landscape keeps amazing me! Even after 11 years of leading the Spring Framework project, I'm learning about new fields of applications, new scenarios to optimize for, and new system architectures to consider. Software development constantly changes, and Spring doesn't just follow along—Spring keeps pushing. The Spring community often anticipates trends before they become heavily debated; for instance, people had been building microservice architectures with Spring long before the term microservice was coined. It is particularly interesting to see how many of the original design decisions behind the framework show their strengths again in 2014: Mechanisms introduced to decouple the framework from the application server infrastructure turn out to be very useful in adapting to modern embedded middleware.

A key mission behind Spring is to keep bringing the latest Java programming model styles to the widest possible range of deployment environments. In the Java community, we tend to put ourselves into straightjackets, not allowing ourselves to use our own current generation of APIs and frameworks. These constraints are primarily due to application server platforms, which contain outdated versions of the JDK and Java EE APIs, lagging behind for way too many years. This situation is particularly critical with Java 8 now: With lambda expressions, the new date-time types, collection streams, and so on, Java 8 has many things to offer that will change your source code style across the codebase. As a community, we need to be able to bring those features into our immediate environments—not just for development, but with full production support.

With Spring 4, we created a new baseline for 2014 and beyond. Spring's comprehensive annotation-oriented programming model is battle-tested, fine-tuned, and as coherent as possible now, and it's designed to be a stable foundation for years to come. We will be extending and refining the framework's functionality in the course of Spring Framework 4.x releases every year, as natural and fully compatible complements to the Spring 4 foundation. We will make a lot of this functionality available to JDK 6+ environments: for updates to existing applications, for deployments to existing data centers, and for corporate environments with conservative JDK policies. At the same time, you will see a strong focus on JDK 8+–oriented functionality with Spring, in particular toward stream- oriented programming and reactive system architectures.

Finally, I have a few personal recommendations to help you get the most out of Spring for your newly started development projects:

First of all, get a good book on core Spring and its design philosophy. With this book, you are beyond that step already.

Don't make compromises up front. Design a clean application architecture based on your understanding of your application's domain.

Start with the latest Java infrastructure that you can possibly bring into production: JDK 8, Spring 4, Tomcat 8, Jetty 9, and so on.

Don't forget to keep updating the frameworks and libraries along with the progress of your own project: Spring, in particular, has been designed for easy upgrades within an application, independent from any server installations.

Beginning Spring focuses on the key principles behind the Spring Framework 4 generation. It is a great way to get started with modern-day Spring development. So free yourself from artificial constraints, and enjoy developing with Spring!

—JÜRGEN HÖLLER

INTRODUCTION

THE SPRING FRAMEWORK IS AN OPEN SOURCE ENTERPRISE APPLICATION framework licensed under Apache License version 2.0, which provides an extensive toolset for building applications that meet the enterprise demands. The idea itself came about because doing development with J2EE (the former version of Java Enterprise Edition) introduced a good deal of complexity in the enterprise world. Creating and deploying beans with Enterprise Java Beans (EJB) was a burden because, to create one bean, you had to create home and component interfaces along with the bean definition. Because the concept of dependency injection was also missing in the EJB world at those times, the lookup approach was the only way to find objects or resources.

The first version of the Spring Framework was based on the code published within Expert One-on-One J2EE Design and Development without EJB (Wrox, 2004) by Rod Johnson and Jürgen Höller. The main idea for the book was to reduce this complexity of enterprise application development with EJBs that was introduced to the EE world with J2EE. The first version of Spring was released in 2002, and milestone releases followed in 2004 and 2005. Version 1.0 brought the lightweight application framework along with features including JDBC abstraction, object relational mapping tools support, transaction management, scheduling and mail abstraction implementations, and the Model View Controller (MVC) web framework.

The 2.0 and 3.0 releases introduced important features to the framework, such as AspectJ support and REST support. At the time of writing this book, version 4.0 was released, and it now complies with the specifications provided by Java Enterprise Edition 7 and with Java 8 Standard Edition, which are the latest versions of Java. Within the book we also try to cover the features of the framework that ships with this latest edition.

Spring gained popularity with its core Dependency Injection (DI) pattern, which is also known as Inversion of Control (IoC). Because object-oriented programming introduces relationships between the objects, the DI approach tries to achieve a loose-coupled design by extracting the management of these dependencies to lead to an easy and manageable implementation. Another spectacular feature of Spring is provided by aspect-oriented programming (AOP), which offers an elegant approach to implementing the cross-cutting concerns in your application. Every web application is in need of features such as exception management, authentication and authorization, logging, and caching. The DI and AOP concepts are covered in detail in Chapters 2 and 8, respectively.

With the help of these major features, Spring provides easily testable, reusable code with no vendor lock-in because it can be ported easily between application servers such as WebLogic, JBoss, and Tomcat. With its layered architecture, it addresses different parts of complex enterprise application development.

We can definitely say that the Spring Framework has become the de facto standard for developing Java enterprise applications. In this book you will find all of the major features brought to the enterprise world by the framework.

WHO THIS BOOK IS FOR

As the book's title states, this book covers the Spring Framework on a beginner level, and it touches on intermediate concepts wherever needed. It explains what the framework offers and also illustrates the content by showing how these features actually work with comprehensive samples. The material presented within the book is suitable for Enterprise application developers who haven't tried the Spring Framework yet or who don't know the details of its core or the subprojects. The book will also be helpful to middle-level management, who will be enlightened about the ingredients of enterprise application development and will get to taste the different flavors of the Spring Framework.

We assume that readers have some knowledge of Java language principles and the ability to develop Java code with integrated development environments (IDEs) such as Eclipse, NetBeans, or others.

This book might not be suitable for people who are not familiar with the Java language and basic object-oriented programming concepts. We also believe that the book might be of no interest for readers who are not keen on the enterprise application development world with Java.

WHAT THIS BOOK COVERS

Spring provides a comprehensive configuration model, both with XML and Java annotations. Throughout the book we demonstrate both annotation-based configuration and XML-based configuration so that we give all the possible configuration scenarios.

The book first focuses on the core concepts and features of the Spring Framework. You take a look at the basic concepts, such as the non-invasive Plain Old Java Object (POJO) programming model approach, and then we define the Dependency Injection pattern (Inversion of Control). Spring also provides a Model View Controller implementation to build web applications; we cover the provided features in detail. The Java Database Connectivity and Java Persistence API features of the Spring Framework are also covered along with the transaction mechanism that it provides. We then focus on what Spring provides for doing test-driven development. Next we cover aspect-oriented programming for giving the reader insight on how Spring handles the implementation for cross-cutting concerns of a system. Spring Expression Languages, caching, and RESTful web services provide extensive features of the Spring Framework, and we cover them with real-world examples that will get you started on development within minutes. Then we dive into Spring Security, which became a de facto standard for applying security constraints on enterprise applications.

The final chapter wraps up the book with the latest features provided by version 4.0 of the framework. We describe the best of the breed because the book covers the major features of Spring by focusing on the latest version of the framework.

The following sections give you just a little bit of detail about what's covered in the 13 chapters of this book.

Dependency Injection and Configuration of Spring

This book covers the core concepts of the Spring Framework such as DI (which is also known as IoC) and its configuration model. The object-oriented programming principles depict having relationships between the objects that are instantiated. The main objective of the DI pattern is to separate the behaviors of those objects from the way that they depend on each other. That way the tenet of loose coupling is achieved with favoring usability and maintainability of the code. The idea of DI originated with Martin Fowler and has become very popular and widely adopted. It's also implemented within popular frameworks such as PicoContainer, Guice, and Spring.

The DI pattern resembles other patterns such as Factory or Strategy. We can say that with the Factory pattern the instantiation of objects is still within the responsibility of the Factory definition, which is your code, but with the DI it's externalized to another component/framework. On the other hand, with the Strategy pattern, the current implementation gets replaced with the help of multiple objects of a same interface, which contain that implementation inside. However, with the DI, the objects that contain those implementations are wired regardless of the implementation defined.

As of version 2.0 of the Spring Framework, the DI mechanism was being configured with the XML schemas along with the support of custom namespaces. As of version 2.5, Spring leveraged the use of Java 5 and the annotations to support auto discovery of components, annotation-driven autowiring of those components, and the life-cycle annotations to hook initialization and destruction callbacks. We cover all of these annotations introduced by the framework.

Spring 4.0

Chapter 13 covers the cutting-edge features of the latest version of Spring. Version 4.0 supports Java 8 with features like lambda expressions and method expressions. It also provides annotation-driven date formatting for the new DateTime API. Version 4.0 also complies with Java EE 7 specifications such as JPA 2.1, JMS 2.0, JTA 1.2, Bean Validation 1.1, and others. We demonstrate these features to give you insight about the best of breed of the most recent version.

Spring Annotations

Spring provides XML-based and annotation-based configuration mainly for dependency injection and also for the other features of the framework. We give the traditional XML configurations with the samples to show the complexity and the burden that they put on the developer. Throughout the book, we favor annotations wherever possible to ease your way and also to make the examples comprehensible in a practical way. We have tried to cover all of the annotations provided by the framework within the samples.

As of Spring 2.5, the JSR-250 Annotations API is also supported. It's the Java Specification Request that has the scope for annotation development, so it makes Spring more compliant with the EE edition of Java.

Spring Persistency Support with JDBC, JPA, and ORM

Spring provides an abstraction to the developers for JDBC database access. It eases development by reducing the boilerplate code for connection management, exception/transaction handling, and preparation and execution of the statements.

Spring doesn't provide a built-in object relational mapping (ORM) framework, but it supports well-known ORM frameworks that comply with the JPA specification, such as Hibernate, EclipseLink, TopLink, and others. The book covers all these features regarding JDBC, JPA, and ORM with step-by-step working samples.

Spring Expression Language (SpEL)

Spring Expression Language (SpEL) is a powerful expression language for navigating through object graphs at run time. All of the SpEL expressions can be defined in XML configurations or with annotations. The syntax used with SpEL resembles Unified EL, but it provides more enhanced features.

SpEL can be used to perform property or bean injections and method invocations. It also supports mathematical and relational operators along with regular expressions. SpEL can be easily used with other subprojects of Spring, such as Security or Caching. It's also technology-agnostic, so it can be used separately without depending on the Spring context. We cover each of these features with self-contained working samples.

Spring Transaction Management and AOP

Data integrity is one of the key points of every system that deals with the data. System behavior such as incorrect account balances, lost orders, or missing entries in a document will definitely be considered unacceptable by the system's users. Transaction management provides a way to achieve integrity on the data. Spring provides extensive transaction management to ensure this data integrity and consistency for enterprise applications. Chapter 6 uses sample code to show how Spring provides declarative and programmatic transaction mechanisms, the differences in local and global transactions, propagation rules on the transactions, and the commit/rollback architecture of the framework.

To implement the cross-cutting concerns, Spring AOP provides easy definition of the elements of AOP with XML configuration, but it also supports the AspectJ framework annotations to easily configure the application.

Spring MVC and Developing RESTful Web Services

With the Model View Controller (MVC) pattern, the enterprise application can be clearly defined with three layers. Model is the part of the application that handles the logic for the application data. View is the part that handles the display of the data, and Controller is the part that handles the user interaction. Spring provides an MVC subproject to handle the HTTP requests by reducing the boilerplate code needed for accessing request parameters, validations, and conversations and model updates. It also provides a convenient way to define RESTful web services to be used with cutting-edge user-interface frameworks to provide more responsive web applications.

Spring Security

Spring Security is the subproject that provides first-class authentication and authorization support for Java-based enterprise applications. The project first started as codename Acegi and then merged into the Spring portfolio. The project conforms to the Servlet API, so it's easy to integrate it with a Java EE–based web application. It also provides optional integration with other Spring frameworks, such as MVC, so it gives consistent usage on its features. In Chapter 12 we provide some neat examples for these feature foundations.

Spring Cache

By starting with version 3.1, Spring Framework provides a transparent caching abstraction for enterprise applications by employing various caching frameworks, such as Ehcache and Hazelcast, in the backend.

The main objective of caching is to reduce the execution of targeted methods by caching the results of method returns with their executed parameters.

NOTE The Spring Framework is a comprehensive toolset that cannot be covered in a beginner-level book with all of its subprojects and the whole set of their features. This book might not be suitable for readers who seek a showdown of Spring subprojects with an end-to-end explanation.

This book also focuses on version4.0.5.RELEASEof the framework, which is the most recent version at the time of writing. Thus the older versions of the framework are not covered with their features in this book.

WHAT YOU NEED TO RUN THE SAMPLES

To run the samples that reside in the book you will need

Java Development Kit (JDK) 8.0

Maven project build and management tool:

You can find all the samples given in the book at

www.wrox.com/go/beginningspring

on the Download Code tab with the Maven-based project structure.

NOTE Maven demands that the Java Development Kit be installed on your local environment instead of the Java Runtime Environment.

A Java web container:

For running the web project samples given throughout the book we've used Tomcat 8.0.12 and Jetty version 9.2.3.

A Java IDE:

The samples given in the book are implemented with Eclipse IDE, but because Maven is used for the project structure, you could build the samples with other IDEs such as NetBeans or IntelliJ IDEA without any difficulty.

CONVENTIONS

To help you get the most from the text and keep track of what's happening, we've used a number of conventions throughout the book.

TRY IT OUT

The Try It Out is an exercise you should work through, following the text in the book.

They usually consist of a set of steps.

Each step has a number.

Follow the instructions in the steps to complete the activity.

How It Works

After each Try It Out, the code you've typed is explained in detail.

WARNING Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.

NOTE Notes, tips, hints, tricks, and asides to the current discussion are offset and placed in italic like this.

As for styles in the text:

We

highlight

new terms and important words when we introduce them.

We show filenames, URLs, and code within the text like so:

persistence.properties

.

We present code in two different ways:

We use a monofont type with no highlighting for most code examples.

We use bold to emphasize code that's particularly important in the present context.

Source Code

As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All of the source code used in this book is available for download at www.wrox.com/go/beginningspring. You will find that the code snippets from the source code are accompanied by a download icon and note indicating the name of the program so you know it's available for download and can easily locate it in the download file. Once at the site, simply locate the book's title (either by using the Search box or by using one of the title lists) and click the Download Code link on the book's detail page to obtain all the source code for the book.

NOTE Because many books have similar titles, you may find it easiest to search by ISBN; this book's ISBN is 978-1-118-89292-3.

After you download the code, just decompress it with your favorite compression tool. Alternatively, you can go to the main Wrox code download page at http://www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

ERRATA

We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece of code, we would be very grateful for your feedback. By sending in errata you may save another reader hours of frustration and at the same time you will be helping us provide even higher quality information.

To find the errata page for this book, go to http://www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the book details page, click the Book Errata link. On this page you can view all errata that has been submitted for this book and posted by Wrox editors. A complete book list including links to each book's errata is also available at www.wrox.com/ misc-pages/booklist.shtml.

If you don't spot “your” error on the Book Errata page, go to www.wrox.com/contact/ techsupport.shtml and complete the form there to send us the error you have found. We'll check the information and, if appropriate, post a message to the book's errata page and fix the problem in subsequent editions of the book.

P2P.WROX.COM

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com you will find a number of different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

Go to

p2p.wrox.com

and click the Register link.

Read the terms of use and click Agree.

Complete the required information to join as well as any optional information you wish to provide and click Submit.

You will receive an e-mail with information describing how to verify your account and complete the joining process.

NOTE You can read messages in the forums without joining P2P, but in order to post your own messages, you must join.

Once you join, you can post new messages and respond to messages other users post. You can read messages at any time on the web. If you would like to have new messages from a particular forum e-mailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

1POJO Programming Model, Lightweight Containers, and Inversion of Control

WHAT YOU WILL LEARN IN THIS CHAPTER:

Problems of the old EJB programming model that triggered the birth of POJO movement

Advantages of the POJO programming model

What a container is and what services it provides to its deployed applications

Lightweight containers and what makes a container lightweight

What Inversion of Control (IoC) means and its importance for applications

Relationship between IoC and dependency injection

Dependency injection methods, setter and constructor injection

Advantages and disadvantages of those different dependency injection methods

The Plain Old Java Object (POJO) movement started around the beginning of the 2000s and quickly became mainstream in the enterprise Java world. This quick popularity is certainly closely related with the open source movement during that time. Lots of projects appeared, and most of them helped the POJO programming model become mature over time. This chapter first closely examines how things were before the POJO programming model existed in the enterprise Java community and discusses the problems of the old Enterprise JavaBeans (EJB) programming model. It's important that you understand the characteristics of the POJO programming model and what it provides to developers.

The second half of the chapter focuses on containers and the inversion of control patterns that are at the heart of the lightweight containers we use today. You learn what a container is, what services it offers, and what makes a container lightweight. You also learn how the inversion of control pattern arises and its close relationship with dependency injection terms. The chapter concludes with an examination of two different dependency injection methods and their pros and cons.

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!