100% found this document useful (1 vote)
104 views

Spring in Action Sixth Edition Craig Walls instant download

Ebook

Uploaded by

jednakolt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
104 views

Spring in Action Sixth Edition Craig Walls instant download

Ebook

Uploaded by

jednakolt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 76

Spring in Action Sixth Edition Craig Walls

install download

https://ebookmeta.com/product/spring-in-action-sixth-edition-
craig-walls/

Download more ebook from https://ebookmeta.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookmeta.com
to discover even more!

Spring Microservices in Action 2nd Edition John Carnell

https://ebookmeta.com/product/spring-microservices-in-action-2nd-
edition-john-carnell/

Spring Security in Action Second Edition MEAP Spilca


Laurentiu

https://ebookmeta.com/product/spring-security-in-action-second-
edition-meap-spilca-laurentiu/

Cloud Native Spring in Action 1st Edition Thomas Vitale

https://ebookmeta.com/product/cloud-native-spring-in-action-1st-
edition-thomas-vitale/

Women s Music for the Screen Diverse Narratives in


Sound 1st Edition Felicity Wilcox (Editor)

https://ebookmeta.com/product/women-s-music-for-the-screen-
diverse-narratives-in-sound-1st-edition-felicity-wilcox-editor/
Performance Trauma and Puerto Rico in Musical Theatre
Routledge Advances in Theatre Performance Studies 1st
Edition Colleen Rua

https://ebookmeta.com/product/performance-trauma-and-puerto-rico-
in-musical-theatre-routledge-advances-in-theatre-performance-
studies-1st-edition-colleen-rua/

Teaching Readers of English Students Texts and Contexts


2nd Edition John S. Hedgcock And Dana R. Ferris

https://ebookmeta.com/product/teaching-readers-of-english-
students-texts-and-contexts-2nd-edition-john-s-hedgcock-and-dana-
r-ferris/

Computation and Approximation 1st Edition Vijay Gupta

https://ebookmeta.com/product/computation-and-approximation-1st-
edition-vijay-gupta/

Can You Tell a Brachiosaurus from an Apatosaurus Buffy


Silverman

https://ebookmeta.com/product/can-you-tell-a-brachiosaurus-from-
an-apatosaurus-buffy-silverman/

Deception Real or Fake News Read along ebook 1st


Edition Dona Herweck Rice

https://ebookmeta.com/product/deception-real-or-fake-news-read-
along-ebook-1st-edition-dona-herweck-rice/
Elementary Algebra 2e Manipulative Mathematics for
Students 1st Edition Lynn Marecek

https://ebookmeta.com/product/elementary-algebra-2e-manipulative-
mathematics-for-students-1st-edition-lynn-marecek/
SIXTH EDITION

Craig Walls

MANNING

From the fifth edition of Spring in Action by Craig Walls

“A great tool for understanding such a complex framework.”

—Arnaldo Gabriel Ayala Meyer, Consultores Informáticos S.R.L.

“Excellent coverage of the latest Spring release with complete


practical examples.”

—Bill Fly, Brookhaven College


“The go-to book for learning the Spring Framework and an excellent
reference guide.”

—Colin Joyce, Cisco

“This has always been my go-to book for Spring. The new edition is
a comprehensive update that strikes the balance between practical
instruction and comprehensive theory. It helps you to get started
quickly and follows up with in-depth explanations.”

—Daniel Vaughan, European Bioinfomatics Institute

“The definitive guide to building cloud native applications using


Spring.”

—David Witherspoon, Parsons Corporation

“The source of truth for the Spring ecosystem.”

—Eddú Meléndez Gonzales, Scotiabank

“I would highly recommend this book, either for newcomers to the


Spring Framework or a seasoned Spring developer who wishes to
deep-dive into the latest features available in the Spring 5
ecosystem.”

—Iain Campbell, Tango Telecom

“Even as a Spring veteran I got lots of practical tips from this book.”

—Jettro Coenradie, Luminis

Spring in Action, Sixth Edition

Spring in Action,

Sixth Edition
CRAIG WALLS

MANNING

SHELTER ISLAND

For online information and ordering of this and other Manning books,
please visit

www.manning.com. The publisher offers discounts on this book


when ordered in quantity.

For more information, please contact

Special Sales Department

Manning Publications Co.

20 Baldwin Road

PO Box 761

Shelter Island, NY 11964

Email: [email protected]

©2022 by Manning Publications Co. All rights reserved.

No part of this publication may be reproduced, stored in a retrieval


system, or transmitted, in any form or by means electronic,
mechanical, photocopying, or otherwise, without prior written
permission of the publisher.

Many of the designations used by manufacturers and sellers to


distinguish their products are claimed as trademarks. Where those
designations appear in the book, and Manning Publications was
aware of a trademark claim, the designations have been printed in
initial caps or all caps.
Recognizing the importance of preserving what has been written, it
is Manning’s policy to have the books we publish printed on acid-free
paper, and we exert our best efforts to that end.

Recognizing also our responsibility to conserve the resources of our


planet, Manning books are printed on paper that is at least 15
percent recycled and processed without the use of elemental
chlorine.

The author and publisher have made every effort to ensure that the
information in this book was correct at press time. The author and
publisher do not assume and hereby disclaim any liability to any
party for any loss, damage, or disruption caused by errors or
omissions, whether such errors or omissions result from negligence,
accident, or any other cause, or from any usage of the information
herein.

Manning Publications Co.

Development editor: Jennifer Stout

20 Baldwin Road

Technical development editor: Joshua White

PO Box 761

Review editor: Mihaela BatinicŚhelter Island, NY 11964

Production editor: Deirdre S. Hiam

Copy editor: Pamela Hunt

Proofreader: Katie Tennant

Technical proofreaders: Doug Warren and German

Gonzalez-Morris
Typesetter: Dennis Dalinnik

Cover designer: Marija Tudor

ISBN: 9781617297571

Printed in the United States of America

brief contents

PART 1

FOUNDATIONAL SPRING ................................................1

Getting started with Spring

Developing web applications

29

Working with data

61

4

Working with nonrelational data

94

Securing Spring

113

Working with configuration properties

140

PART 2

INTEGRATED SPRING . ................................................161

Creating REST services

163

Securing REST
186

Sending messages asynchronously

210

10

Integrating Spring

243

PART 3

REACTIVE SPRING . ....................................................277

11

Introducing Reactor

279

12

Developing reactive APIs

308

vii
viii

BRIEF CONTENTS

13

Persisting data reactively

337

14

Working with RSocket

369

PART 4

DEPLOYED SPRING ....................................................385

15

Working with Spring Boot Actuator

387

16

Administering Spring

423
17

Monitoring Spring with JMX

435

18

Deploying Spring

443

contents

preface

xvii

acknowledgments

xix

about this book

xxi

about the author

xxv

about the cover illustration

xxvi

PART 1
FOUNDATIONAL SPRING ......................................1

1 Getting started with Spring 3

1.1

What is Spring?

1.2

Initializing a Spring application

Initializing a Spring project with Spring Tool Suite

Examining the Spring project structure

11

1.3

Writing a Spring application

17

Handling web requests

18 ■ Defining the view

19

Testing the controller

20 ■ Building and running the


application

21 ■ Getting to know Spring Boot DevTools

23

Let’s review

25

1.4

Surveying the Spring landscape

26

The core Spring Framework

26 ■ Spring Boot

26 ■ Spring

Data

27 ■ Spring Security

27 ■ Spring Integration and Spring

Batch

27 ■ Spring Cloud

28 ■ Spring Native

28

ix

x
CONTENTS

2 Developing web applications 29

2.1

Displaying information

30

Establishing the domain

31 ■ Creating a controller class

34

Designing the view

38

2.2

Processing form submission

41

2.3

Validating form input

49

Declaring validation rules

50 ■ Performing validation at

form binding

52 ■ Displaying validation errors


54

2.4

Working with view controllers

54

2.5

Choosing a view template library

57

Caching templates

59

3 Working with data 61

3.1

Reading and writing data with JDBC

62

Adapting the domain for persistence

64 ■ Working with

JdbcTemplate

65 ■ Defining a schema and preloading

data

70 ■ Inserting data

73
3.2

Working with Spring Data JDBC

78

Adding Spring Data JDBC to the build

78 ■ Defining

repository interfaces

79 ■ Annotating the domain for

persistence

81

Preloading data with CommandLineRunner

83

3.3

Persisting data with Spring Data JPA

85

Adding Spring Data JPA to the project

85 ■ Annotating the

domain as entities

86 ■ Declaring JPA repositories

89

Customizing repositories
90

4 Working with nonrelational data 94

4.1

Working with Cassandra repositories

95

Enabling Spring Data Cassandra

95 ■ Understanding

Cassandra data modeling

98 ■ Mapping domain types

for Cassandra persistence

99 ■ Writing Cassandra

repositories

105

4.2

Writing MongoDB repositories

106

Enabling Spring Data MongoDB

106 ■ Mapping domain

types to documents

107 ■ Writing MongoDB repository


interfaces

111

CONTENTS

xi

5 Securing Spring 113

5.1

Enabling Spring Security

114

5.2

Configuring authentication

116

In-memory user details service

118 ■ Customizing user

authentication

119

5.3

Securing web requests

125

Securing requests

125 ■ Creating a custom login page


128

Enabling third-party authentication

131 ■ Preventing cross-site

request forgery

133

5.4

Applying method-level security

134

5.5

Knowing your user

136

6 Working with configuration properties 140

6.1

Fine-tuning autoconfiguration

141

Understanding Spring’s environment abstraction

142

Configuring a data source

143 ■ Configuring the embedded

server
145 ■ Configuring logging

146 ■ Using special

property values

148

6.2

Creating your own configuration properties

148

Defining configuration property holders

151 ■ Declaring

configuration property metadata

153

6.3

Configuring with profiles

155

Defining profile-specific properties

156 ■ Activating profiles

158

Conditionally creating beans with profiles

159

PART 2
INTEGRATED SPRING .......................................161

7 Creating REST services 163

7.1

Writing RESTful controllers

164

Retrieving data from the server

164 ■ Sending data to the

server

170 ■ Updating data on the server

171 ■ Deleting data

from the server

173

7.2

Enabling data-backed services

174

Adjusting resource paths and relation names

177 ■ Paging and

sorting

179

7.3
Consuming REST services

180

GETting resources

182 ■ PUTting resources

183

DELETEing resources

184 ■ POSTing resource data

184

xii

CONTENTS

8 Securing REST 186

8.1

Introducing OAuth 2

187

8.2

Creating an authorization server

192

8.3

Securing an API with a resource server

201
8.4

Developing the client

204

9 Sending messages asynchronously 210

9.1

Sending messages with JMS

211

Setting up JMS

211 ■ Sending messages with JmsTemplate

214

Receiving JMS messages

222

9.2

Working with RabbitMQ and AMQP

226

Adding RabbitMQ to Spring

227 ■ Sending messages with

RabbitTemplate

228 ■ Receiving messages from RabbitMQ

232
9.3

Messaging with Kafka

236

Setting up Spring for Kafka messaging

237 ■ Sending messages

with KafkaTemplate

238 ■ Writing Kafka listeners

241

10 Integrating Spring 243

10.1

Declaring a simple integration flow

244

Defining integration flows with XML

246 ■ Configuring

integration flows in Java

247 ■ Using Spring Integration’s

DSL configuration

249

10.2

Surveying the Spring Integration landscape


251

Message channels

252 ■ Filters

253 ■ Transformers

254

Routers

256 ■ Splitters

257 ■ Service activators

260

Gateways

262 ■ Channel adapters

263 ■ Endpoint

modules

265

10.3

Creating an email integration flow

267

PART 3

REACTIVE SPRING ...........................................277

11 Introducing Reactor 279


11.1

Understanding reactive programming

280

Defining Reactive Streams

281

11.2

Getting started with Reactor

283

Diagramming reactive flows

285 ■ Adding Reactor

dependencies

286

CONTENTS

xiii

11.3

Applying common reactive operations

287

Creating reactive types

287 ■ Combining reactive types

291
Transforming and filtering reactive streams

295 ■ Performing

logic operations on reactive types

305

12 Developing reactive APIs 308

12.1

Working with Spring WebFlux

309

Introducing Spring WebFlux

310 ■ Writing reactive controllers

312

12.2

Defining functional request handlers

316

12.3

Testing reactive controllers

320

Testing GET requests

320 ■ Testing POST requests

323
Testing with a live server

324

12.4

Consuming REST APIs reactively

325

GETting resources

326 ■ Sending resources

328 ■ Deleting

resources

329 ■ Handling errors

329 ■ Exchanging requests

331

12.5

Securing reactive web APIs

333

Configuring reactive web security

333 ■ Configuring a reactive

user details service

335

13 Persisting data reactively 337


13.1

Working with R2DBC

338

Defining domain entities for R2DBC

339 ■ Defining reactive

repositories

343 ■ Testing R2DBC repositories

345 ■ Defining

an OrderRepository aggregate root service

347

13.2

Persisting document data reactively with MongoDB

353

Defining domain document types

354 ■ Defining reactive MongoDB

repositories

356 ■ Testing reactive MongoDB repositories

357

13.3

Reactively persisting data in Cassandra


361

Defining domain classes for Cassandra persistence

362

Creating reactive Cassandra repositories

365 ■ Testing reactive

Cassandra repositories

366

14 Working with RSocket 369

14.1

Introducing RSocket

370

14.2

Creating a simple RSocket server and client

372

Working with request-response

372 ■ Handling request-stream

messaging

376 ■ Sending fire-and-forget messages

378

Sending messages bidirectionally


379

14.3

Transporting RSocket over WebSocket

382

xiv

CONTENTS

PART 4

DEPLOYED SPRING ..........................................385

15 Working with Spring Boot Actuator 387

15.1

Introducing Actuator

388

Configuring Actuator’s base path

389 ■ Enabling and disabling

Actuator endpoints

390

15.2

Consuming Actuator endpoints

391

Fetching essential application information


392 ■ Viewing

configuration details

395 ■ Viewing application activity

403

Tapping runtime metrics

405

15.3

Customizing Actuator

408

Contributing information to the /info endpoint

408 ■ Defining

custom health indicators

414 ■ Registering custom metrics

415

Creating custom endpoints

417

15.4

Securing Actuator

420

16 Administering Spring 423


16.1

Using Spring Boot Admin

424

Creating an Admin server

424 ■ Registering Admin

clients

426

16.2

Exploring the Admin server

427

Viewing general application health and information

428

Watching key metrics

428 ■ Examining environment

properties

429 ■ Viewing and setting logging levels

431

16.3

Securing the Admin server

431
Enabling login in the Admin server

432 ■ Authenticating

with the Actuator

433

17 Monitoring Spring with JMX 435

17.1

Working with Actuator MBeans

435

17.2

Creating your own MBeans

437

17.3

Sending notifications

440

18 Deploying Spring 443

18.1

Weighing deployment options

444

18.2

Building executable JAR files


445

CONTENTS

xv

18.3

Building container images

446

Deploying to Kubernetes

449 ■ Enabling graceful shutdown

451

Working with application liveness and readiness

452

18.4

Building and deploying WAR files

455

18.5

The end is where we begin

457

appendix

Bootstrapping Spring applications

459
index

479

preface

Spring entered the development world more than 18 years ago with
the fundamental mission of making Java application development
easier. Originally, that meant offering a lightweight alternative to EJB
2.x. But Spring was just getting started. Over the years, Spring
expanded its mission of simplicity to address common development
challenges, including persistence, security, integration, cloud
computing, and others.

Although Spring is closing in on two decades of enabling and


simplifying enterprise Java development, it shows no signs of
slowing down. Spring continues to address Java development
challenges, whether it be creating an application deployed to a
conventional application server or a containerized application
deployed to a Kubernetes cluster in the cloud. And with Spring Boot
providing autoconfiguration, build dependency help, and runtime
monitoring, there has never been a better time to be a Spring
developer!

This edition of Spring in Action is your guide to Spring and Spring


Boot and has been updated to reflect the best of what both have to
offer. Even if you’re new to Spring, you’ll have your first Spring
application up and running before the end of the first chapter. As the
book progresses, you’ll learn how to create web applications, work
with data, secure your application, and manage application
configuration. Next, you’ll explore options for integrating your Spring
applications with other applications and how to benefit from reactive
programming in your Spring applications, including the new RSocket
communication protocol. As the book draws to a close, you’ll see
how to prepare your application for production and learn options for
deploying.
xvii

xviii

PREFACE

Whether you’re new to Spring or have many years of Spring


development to your credit, this is your next step in your journey.
I’m excited for you and happy to bring this guide to you. I look
forward to seeing what you create with Spring!

acknowledgments

One of the most amazing things that Spring and Spring Boot do is
automatically provide all of the foundational plumbing for an
application, leaving you as a developer to focus primarily on the logic
that’s unique to your application. Unfortunately, no such magic exists
for writing a book. Or does it?

At Manning, several people worked their magic to make sure that


this book is the best it can possibly be. Many thanks in particular to
my development editor, Jenny Stout, and to production editor,
Deirdre Hiam, copy editor, Pamela Hunt, graphics editor, Jennifer
Houle, and the entire production team for their wonderful work in
making this book a reality.

As the book was forming, we had several peer reviewers take an


early look, give us feedback, and help make sure that the book
stayed on target and covered the right stuff. For this, my thanks go
to Al Pezewski, Alessandro Campeis, Becky Huett, Chris-tian
Kreutzer-Beck, Conor Redmond, David Paccoud, David Torrubia
Iñigo, David Witherspoon German Gonzalez-Morris, Iain Campbell,
Jon Guenther, Kevin Liao, Mark Dechamps, Michael Bright, Philippe
Vialatte, Pierre-Michel Ansel, Tony Sweets, William Fly, and Zorodzayi
Mukuya.
I absolutely must give a shout out to everyone on the Spring
engineering team.

You consistently produce some of the most incredible stuff I’ve ever
worked with, and I am proud to consider you my colleagues.

Many thanks go to my fellow speakers on the No Fluff/Just Stuff


tour. I continue to learn so much from every one of you. And many
thanks to those of you who have xix

xx

ACKNOWLEDGMENTS

attended one of my sessions on the NFJS tour; although I’m the one
at the front of the room, I often learn a lot from you, too.

As I did in the previous edition, I’d like to thank the Phoenicians. You
know what you did.

Finally, to my beautiful wife, Raymie, the love of my life and my


sweetest dream: thank you for your encouragement and for putting
up with yet another book project.

And to my sweet and wonderful girls, Maisy and Madi: I am so proud


of you and of the amazing young ladies you are becoming. I love all
of you more than you can possibly know or words can express.

about this book

Spring in Action, Sixth Edition, was written to equip you to build


amazing applications using the Spring Framework, Spring Boot, and
a variety of ancillary members of the Spring ecosystem. It begins by
showing you how to develop web-based, database-backed Java
applications with Spring and Spring Boot. It then expands on the
essentials by showing how to integrate with other applications and
programs using reactive types. Finally, it discusses how to ready an
application for deployment.

Although all of the projects in the Spring ecosystem provide


excellent documentation, this book does something that none of the
reference documents do: provide a hands-on, project-driven guide to
bringing the elements of Spring together and build a real application.

Who should read this book

Spring in Action, Sixth Edition, is for Java developers who want to


get started with Spring Boot and the Spring Framework as well as
for seasoned Spring developers who want to go beyond the basics
and learn the newest features of Spring.

How this book is organized: A roadmap

The book has four parts spanning 18 chapters. Part 1 covers the
foundational topics of building Spring applications:

 Chapter 1 introduces Spring and Spring Boot and how to initialize


a Spring project. In this chapter, you’ll take the first steps toward
building a Spring application that you’ll expand on throughout the
course of the book.

xxi

xxii

ABOUT THIS BOOK

 Chapter 2 discusses building the web layer of an application using


Spring MVC.

In this chapter, you’ll build controllers that handle web requests and
views that render information in the web browser.
 Chapter 3 delves into the backend of a Spring application, where
data is persisted to a relational database.

 Chapter 4 continues the subject of data persistence by looking at


how to persist data to nonrelational databases, specifically,
Cassandra and MongoDB.

 In chapter 5, you’ll use Spring Security to authenticate users and


prevent unauthorized access to an application.

 Chapter 6 reveals how to configure a Spring application using


Spring Boot configuration properties. You’ll also learn how to
selectively apply configuration using profiles.

Part 2 covers topics that help integrate your Spring application with
other applications:

 Chapter 7 expands on the discussion of Spring MVC started in


chapter 2, by looking at how to write and consume REST APIs in
Spring.

 Chapter 8 shows how to secure the APIs created in chapter 7,


with Spring Security and OAuth 2.

 Chapter 9 looks at using asynchronous communication to enable


a Spring application to both send and receive messages using the
Java Message Service, RabbitMQ, or Kafka.

 Chapter 10 discusses declarative application integration using the


Spring Integration project.

Part 3 explores the exciting new support for reactive programming in


Spring:

 Chapter 11 introduces Project Reactor, the reactive programming


library that underpins Spring 5’s reactive features.
 Chapter 12 revisits REST API development, introducing Spring
WebFlux, a new web framework that borrows much from Spring
MVC while offering a new reactive model for web development.

 Chapter 13 takes a look at writing reactive data persistence with


Spring Data to read and write data to Cassandra and Mongo
databases.

 Chapter 14 introduces RSocket, a new communication protocol


that offers a reactive alternative to HTTP for creating APIs.

In part 4, you’ll ready an application for production and see how to


deploy it:

 Chapter 15 introduces the Spring Boot Actuator, an extension to


Spring Boot that exposes the internals of a running Spring
application as REST endpoints.

 In chapter 16, you’ll see how to use Spring Boot Admin to put a
user-friendly browser-based administrative application on top of the
Actuator.

 Chapter 17 discusses how to expose and consume Spring beans


as JMX MBeans.

ABOUT THIS BOOK

xxiii

 Finally, in chapter 18, you’ll see how to deploy your Spring


application in a variety of production environments, including
Kubernetes.

In general, developers new to Spring should start with chapter 1 and


work through each chapter sequentially. Experienced Spring
developers may prefer to jump in at any point that interests them.
Even so, each chapter builds on the previous one, so there may be
some context missing if you dive into the middle of the book.

About the code

This book contains many examples of source code, both in


numbered listings and inline with normal text. In both cases, source
code is formatted in a fixed-width font like this to separate it from
ordinary text.

In many cases the original source code has been reformatted; we’ve
added line breaks and reworked indentation to accommodate the
available page space in the book. In rare cases, even this was not
enough, and listings include line-continuation markers (➥).
Additionally, comments in the source code have often been removed
from the listings when the code is described in the text. Code
annotations accompany many of the listings, highlighting important
concepts.

You can get executable snippets of code from the liveBook (online)
version of this

book at https://livebook.manning.com/book/spring-in-action-sixth-
edition. The complete code for the examples in the book is available
for download from the Manning website at
https://www.manning.com/books/spring-in-action-sixth-edition, and
from

GitHub at github.com/habuma/spring-in-action-6-samples.

Book forum

Purchase of Spring in Action, Sixth Edition, includes free access to


liveBook, Manning’s online reading platform. Using liveBook’s
exclusive discussion features, you can attach comments to the book
globally or to specific sections or paragraphs. It’s a snap to make
notes for yourself, ask and answer technical questions, and receive
help from the author and other users. To access the forum, go to
https://forums.manning.com/

forums/spring-in-action-sixth-edition. You can also learn more about


Manning’s forums and the rules of conduct at
https://forums.manning.com/forums/about.

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 forum remains voluntary (and unpaid). We
suggest you try asking the author some challenging questions lest
his interest stray! The forum and the archives of previous
discussions will be accessible from the publisher’s website as long as
the book is in print.

xxiv

ABOUT THIS BOOK

Other online resources

Need additional help?

 The Spring website has several useful getting-started guides


(some of which were written by the author of this book) at
https://spring.io/guides.

 The Spring tag at Stack Overflow


(https://stackoverflow.com/questions/tagged/

spring) as well as the Spring Boot tag at Stack Overflow


(https://stackoverflow

.com/questions/tagged/springboot) are great places to ask questions


and help others with Spring. Helping someone else with their Spring
questions is a great way to learn Spring!

about the author

CRAIG WALLS is a senior engineer with VMware. He’s a zealous


promoter of the Spring Framework, speaking frequently at local user
groups and conferences and writing about Spring. When he’s not
slinging code, Craig is planning his next trip to Disney World or
Disneyland and spending as much time as he can with his wife, two
daugh-ters, three dogs, and a parrot.

xxv

about the cover illustration

The figure on the cover of Spring in Action, 6th edition, is “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 surround-
ing 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 phe-nomenon 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 dis-tinctiveness 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
inhabitants 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.

xxvi

Part 1

Foundational Spring

Part 1 of this book will get you started writing a Spring application,
learning the foundations of Spring along the way.

In chapter 1, I’ll give you a quick overview of Spring and Spring Boot
essentials and show you how to initialize a Spring project as you
work on building Taco Cloud, your first Spring application. In chapter
2, you’ll dig deeper into the Spring MVC and learn how to present
model data in the browser and how to process and validate form
input. You’ll also get some tips on choosing a view template library.
You’ll add data persistence to the Taco Cloud application in chapter
3, where we’ll cover using Spring’s JDBC template and how to insert
data using prepared statements and key holders. Then you’ll see
how to declare JDBC (Java Database Connectivity) and JPA (Java
Persistence API) repositories with Spring Data. Chapter 4 continues
the Spring persistence story by looking at two more Spring Data
modules for persisting data to Cassandra and MongoDB.

Chapter 5 covers security for your Spring application, including


autoconfiguring Spring Security, defining custom user storage,
customizing the login page, and securing against cross-site request
Other documents randomly have
different content
Alas! alas! zeal
without knowledge is
a terrible thing. Poor
Dab cannot possibly
do just what he is
told; he has to plan
some original course
for himself.

I went to meet
my friend unduly "Jus' shinin' um up wid de
agitated and upset by knife-brick."
the circumstance, but
was careful not to
speak of it. I can bear
things so much better if I do not mention them to any one until the
pang is all gone. That is why this little diary is so much to me. I can
explode into it, and then shut my teeth and bear things.

Unpacked the incubator to-day with Bonaparte's help and began


to study its mysteries. We had a time getting things right, for he has
never seen or dreamed of an incubator, and disapproves entirely of
the effort to take away the occupation of the hen and defeat nature,
so that his manner was disapproving, not to say forbidding. My good
Chloe, too, feels that for some unknown reason the Great Father has
given me over to the temptation of the Evil One, and walks past the
"'cubator," as she calls it, with head high and firm tread; her manner
is what the "nigs" call "stiff"—that means distinctly rebellious and
unconvinced. I had only seen an incubator myself for five minutes
under the rapid flow of words from the young man exhibiting it,
words of fervid praise and faith which left me somewhat vague and
confused as to details, for it was just in a shop and not working.
I calculated when I bought it that I would have time to try my
'prentice hand with fowl eggs, which take only three weeks to hatch,
and then fill it with turkey eggs, which take four weeks, and get
them out before I have to leave home on May 8; but unfortunately
the steamboat was detained by a storm and so the incubator was
delayed a whole week, which threw out all my plans, and I will have
to give up the turkey eggs. The little book, which is wonderfully
explicit and satisfactory, says one should study out the management
of the heat thoroughly before putting in the eggs, and that will make
some delay.
April 6.

I have sat on a low stool in front of the incubator day and night
since it was unpacked and installed in the drawing-room. I lighted
the lamp at once, and then watched the thermometer, which
necessitates a bright light and a very low seat. I thought it was
going to be very simple, and on the second day I thought I had it
steady at 102½ degrees, and went off into the field to see after
some ploughing. When I came back I rushed in to see if it was
holding its own and found the mercury at 110 degrees—one little
step more and it would have broken the thermometer. After that I
just stayed there. The thermostat is a wonderfully delicate piece of
mechanism and I have no one to consult.
April 7.

At last I have got the thermometer to remain steadily at 102½


for ten hours, so to-night at 6 o'clock I put in the 120 eggs.
April 10.

Tested eggs to-day. Only six infertile. The thermostat is working


beautifully and the mercury does not vary a half degree during the
twenty-four hours. I am very careful to follow absolutely every
direction and let no one touch it but myself, for I wish to give it a fair
trial. All my friends in the county are confiding to each other their
anxiety over my venture. "Such a pity dear Patience should have
wasted her money on such a folly. A huge sum, $25, for those two
machines. It is distressing." Many years ago, when incubators were
first invented, a progressive neighbor invested in one, and the lamps
exploded and a serious fire resulted, so that it is only natural that
incubators are much looked down on in this community. No doubt
there have been great improvements, and I must think mine the
most perfect of all. Still, I feel great anxiety as to the results, for I
will have not only the great disappointment and loss should it fail but
also the "I told you so" of the whole country side.
April 11.

Began to mix the inoculating stuff for the alfalfa, boiling rain-
water for the purpose. Elihu has ploughed with the heavy plough
and Ball and Paul in the alfalfa field. Gibbie comes behind in the
same furrow with Jack and Sambo and a bull tongue plough. They
have gone very deep and the land should be in good fix after it.
Made Willing try the Cahoon seeder to see if it worked according to
directions on card.
April 12.

Elihu and Gibbie harrowing alfalfa field. I had a large tub on the
piazza and put in the second ingredient for the wonder bath. I
bought a corn planter this spring, not because I plant enough corn
to really need it, but because the crooked planting of the women
worries me so. To-day we were to plant the first acre of corn for this
season. I had Willing use the planter drawn by Mollie. It worked very
well, but he could not go straight and the rows look like snake
tracks, much worse than the women's planting, and I had much
better have saved my $10. Bonaparte is triumphant and I am in the
slough of despond.
April 13.

Planted corn again. Had Elihu to run corn planter and had Willing
to take his place harrowing in alfalfa field. The rows are a little
straighter, but still hopelessly meandering. That $10 is simply thrown
away.
April 14.

What a time I have had to-day. I started out to plant four acres
of alfalfa and I feel just as though I had drawn the plough and the
harrow as well as the three darkies. The land has been double
ploughed, then harrowed with a home-made tooth harrow, and then
with the acme several times. The land was heavily covered with
stable manure before the ploughing. I have mixed the wonder bath
most accurately and now the culmination of all, the planting, was to
take place. I bought a Cahoon broadcast seeder, and have tried to
make Willing (the boy I have in Jim's place, but oh, what a misfit!)
understand the directions. I called upon old Bonaparte this morning
to measure the seed out into separate sacks, so that we would have
no confusion in the field, but, oh, dear, what a dream that was! It
seemed to Bonaparte such feminine folly that I should insist on
stakes every ten feet at the head and end of the field so that Willing
would have something to guide his wandering steps. We have had
high words on the subject, he maintaining that it was a waste of
labor and stakes to mark anything but the half acre. As Willing has
not a straight eye and walks a good deal as though he were tipsy,
even with the guiding stakes, I think it will be in the nature of a
miracle if this field is covered with alfalfa. I have not been out here
for two or three days, as I was planting corn, but I had two men and
two teams at work all the time and a woman to clear away roots,
etc., and positively I do not see what they have done. The field is as
rough as possible, it seems to me, though the negroes think me
most unreasonable and Elihu says: "My Lor', Miss, wha' yo' want
mo'? Dis fiel' look too bu-ti-ful, 'e stan' same lik' a gya'ding!"

The first difficulty is to get the stakes set straight, a tall and then
a short, so that Willing will know that when he leaves a short stake
he must reach a short one at the end of the field; but I had a perfect
battle to get Bonaparte to set the stakes in that way. The next
trouble was to get rid of the alfalfa—I allowed ten quarts to the acre,
and it will not go in. I have opened the small door of the conceited
Cahoon creature just one-half inch as the card says, and made
Willing walk every ten feet instead of every twenty, as it directs, and
yet the peck of seed holds out and is left over.

I understand some of men's temptations in the way of speech


now as I never did before.

Just here I am in trouble over the whereabouts of a huge


caterpillar of varied and gorgeous colors which I saw a moment ago
very near me. I did not like to shorten its little span of life, so I took
it on a big leaf to quite a distance from where I was sitting and
turned it on its back and made a little pen around it. Now it has
disappeared and it may be anywhere. I must move to another tree,
though I have an ideal seat on the root of this one, a splendid live
oak with spreading branches.

Finding the ground still so rough I sent Elihu to "the street" to


get a woman with a hoe to go over the ground and remove
impediments. I said: "Get any one you can at once," thinking he
would bring Snippy his wife, or Susan his daughter; but in a short
time I saw a procession arriving. Aphrodite, with a basket on her
head, a baby in one arm and a child of eighteen months dragging by
the other hand, while one of three years toddled behind. The
procession moved to a clump of trees in the middle of the field;
there Aphrodite made a halt, took from her basket a quilt, and
sp
re
a
di
n
g
it
o
n
th
Aphrodite spread a quilt and deposited e
the party upon it. gr
o
u
n
d deposited the party upon it. I do wish I had my kodak; but I am so
stupid about the films; I cannot put them in myself, and I am so
afraid of spending an unnecessary cent, that for months my kodak is
no use to me, and it would be such a delight if I could only once
learn its intricacies.

This group has saved my reason to-day, I think, for the little
things are so funny, solemnly staring around, a bucket of rice and
meat made into a strange mess in the midst. I sent for a basket of
roast sweet potatoes, and gave one to each, but I disturbed the
peace of the pastoral, for I insisted that the potato should be peeled
for the baby, whereupon Isaiah set up a terrible yell and Aphrodite
said: "Him lub de skin." I insisted, however, that the skin should be
removed, for only a month ago Isaiah was at death's door with
convulsions. The baby has on a little red frock and a little red cap
with frills, tied tightly on her little coal black head, and the sun is
broiling hot. Her name is Florella Elizabeth Angelina.
But back to the precious alfalfa, which has cost me so much
worry as well as money All that I can get put into the land is six
quarts to the acre. Here I pause with pleasure as another procession
approaches. Oh, for my kodak again. I heard a noise, and on looking
up I see the Imp puffed up with pride rolling the wheelbarrow, which
seems to have a large and varied load. Behind comes my little maid
Gerty with a basket. With a great swing Imp rolls the wheelbarrow
alongside of me; and they proceed to unload. First a little green
painted table, which has a history that perhaps some day I will have
time to tell; then Gerty takes from her basket table-cloth and table
napkins of snowy damask and all the implements and
accompaniments of a modern lunch. Imp takes out a demijohn of
artesian water, the cut glass salt cellar, pepper cruet, and then these
are put in position and in the midst a little dish of butter, churned
since I left the house this morning; and what a nice dinner! A fresh
trout with a roe, brought me an hour ago as a present from Casa
Bianca by Nat, broiled to a turn—a delicious morsel, and after that
an abundant dish of asparagus, and besides this a large dish of fried
bacon and one of rice.

"Oh, Gerty," I said. "Chloe knew I did not want all this to eat."

"Yes, ma'am," she answered. "An' Chloe say to tell you say we
got plenty home for dinner en she know yu'd like to give some 'way."
That made me happy, for Chloe to understand me so thoroughly, to
send me a delicious dainty meal for myself, and then besides a
substantial portion for me to give away. That is what an old time,
before the war darky is, one whose devotion makes them enter into
one's tastes and feelings so thoroughly.

When I left the house this morning I certainly expected to be


back to dinner, but finding how absolutely necessary my presence in
the field was I just stayed there, and at three Chloe sent this nice
meal. When the procession arrived I exclaimed, "How delightful!
Whose idea was the wheelbarrow?" The Imp answered promptly:
"De me, ma'am," at which I made him my compliments. It is such a
pleasure to be able to commend the poor little Imp, for he has an
immense ingenuity in mischief and earns much reproof.

I am quite ashamed of the frame of mind in which I began this,


but I will not tear it up. What is written is written. After this episode
everything looks so different, and now at 4:30 the four acres are
planted and 22-year-old Mollie is drawing a bush over to cover the
seed with such rapidity that she keeps Elihu at a run, and even to
my eye the field looks fairly respectable, and the darkies think it
unspeakably fine. I am making Willing travel over between the
tracks where he went before, and so have disposed of the necessary
quantity of seed to within a peck. Now I can look up and beyond the
gray earth and glory in the beauty of God's world. Half of the field
was planted in oats in the winter and it is now splendid, an expanse
of intense vivid color. The field, about twenty acres, is a slight
elevation surrounded on three sides by a swamp, in which the
variety of young green is wonderful. The cypress with its feathery
fringe of pale grass green, the water oak with its tender yellow
green, the hickory with its true pure green, and the maple with its
gamut of pink up and down the scale—pale salmon, rose pink, then
a brick-dusty pink, and here at last it rises into rich crimson. Here
and there the poplar, with its flowerlike leaves, the black gum with
its black tracery of downward turning branches, all edged with
tender gray green.

It is too beautiful for words, and behind all, accenting and


bringing out the light airy beauty, is the dark blue green of the
solemn pine forest. I wish I had brought my crayons and block; I
might have had a faint echo of one little corner to send to some
poor shut-in who cannot get it first hand in its exquisite reality. And
this, too, is but a prelude; in a few days the ideal tenderness will be
replaced by a more material and lasting beauty, but not so heart
reaching. It certainly seems a pity that one should have to think of
and strive after filthy lucre in the midst of all this beauty; but I have
reached a point where if I do not struggle and wrestle with the
earth, therefrom to draw the said dross, I will have to give up all this
life with Nature and find a small room in some city to eke out my
days.

It is not a cheap thing to live in this country. One must have


horses, one must have servants—but once given a moderate income
to cover these things and there is no spot on earth where one can
have so much for so little. Wild ducks abound all winter, also
partridges, snipe, and woodcock; rabbits and squirrels run over
everything. Our streams are filled with bream, Virginia perch and
trout. If any one wants better living than these afford, he can have
wild turkey and venison for the shooting, as the woods abound in
these, and he can have shad daily during two months if he goes to
the expense of a small shad net and a man to use it. It is a splendid
country for poultry. Turkeys, ducks, and chickens are easily raised,
and I believe it could be made to pay handsomely.

My first question to Gerty when she appeared to-day was, "How


high is the incubator?" She answered promptly 101, by which I know
it is not above 103, and am thankful. I fear the eggs are all cooked,
for when I got in from the corn-field Thursday the mercury stood
106½. I had left Gerty to watch and to open the door if it went
above 102½. She reads and writes and knows the figures quite well,
but does not seem to understand the thermometer.
April 20.

I had told Aphrodite that she must pull up all the grass roots,
brambles, etc., in the alfalfa field; as it was new ground the harrow
had not got them all out. She came to me to-day and said:—
"Miss, I kyan't wuk een dat fiel' no mo'; de ting cum up too
purty, en ef I tromple um I'll kill um."

"Do you mean the alfalfa has come up?"

"Yes, ma'am, de whol' fiel' kiver wid um."

I just flew to the field on my bicycle, and truly there was the
whole field covered with tiny dark gray green leaves! I was perfectly
delighted, for I had not supposed it would come so quickly and had
no idea the stand could be so thick after all my tribulations.

Just before lunch S. came, bringing some friends with her—they


wished to see how I turned the eggs in the incubator, and so I took
the tray out to show them, and as I was putting it down on the table
I heard a very soft chirp, which startled me so that I nearly dropped
the whole thing.

Somehow I had not realized that the time was so near for the
climax, but to-night as I was going to bed I went for a last look, and
there was one little chick, white and fluffy and very lively. I wonder if
that is to be the only one.
April 28.

The whole incubator seems to have turned into chickens. I never


saw anything like it but a swarm of bees. As soon as I got up this
morning I rushed down to the incubator, and there they were!

I called Chloe at once, and she stood in front of the glass door
and gazed with wondering eyes, then she dropped a profound
courtesy, and, raising her eyes and hands to heaven, she said,
"T'ank de Laud," and this was repeated three times with intense
fervor and reverence. Then she seized my hand and shook it
violently.
Only then did I understand how much self-control Chloe had
used not to show me more plainly her utter doubt and scorn of the
'cubator. I knew she did not approve, but had no idea that she felt
certain we would never see a chicken from it. Her delight is
unbounded.

The book of instructions says you must not open the door at all
after the eggs begin to pip, but I had to open it very quickly and
take out the egg-shells which were so much in the way of the chicks.
It is too bad that they sent the brooder without any lamp, and so I
cannot take the chicks out as I should do when they are twelve
hours old.

The incubator must be kept at from 105 degrees, and the newly
hatched chicks only 101 degrees, or at most 102, and so I am afraid
of roasting the chicks or chilling the eggs.
April 29.

I am in a great quandary about the chickens, and I have to go to


Gregory to meet a cousin at the train, for I cannot trust Willing to
drive across the ferry and go to the station alone; he is too poor a
driver, and so I must go myself. A great many eggs are pipped and
the chicks will be sacrificed if I leave them so crowded and so hot.

After thinking it over I made up my mind, took a basket, opened


the door of the incubator, took out thirty eggs which had not
hatched, and going to the river threw them in. I stood on the little
wooden landing and watched, and to my horror the eggs swam!

They would not go with the tide but made a circle and returned
to the shore, and I felt like a murderer, but I could not get them
back, so I sadly returned to the house and reduced the heat in the
incubator to 102 and fed the chicks some bread crumbs. Then I got
into the wagon and started for Gregory.
It was dark when we got to the ferry and I did not reach the
Winyah Inn until 10 o'clock.
April 30.

When Willing drove to the inn for me this morning I saw a large
red object protruding from his pocket, and as we drove to the
station I asked him what it was. He appeared very much confused
and would not answer, so I told him to take the thing out, as it
looked very badly.

Finally with much difficulty I made him take it out before we


reached the station, and it was a quart bottle of dispensary whiskey!
I was very angry and told him to hand it to me, which he at first
refused to do, but in the end he did, and I put it in my valise.

I told him I was greatly mortified and disappointed that this first
time I had trusted him to drive me to town he should do such a
thing. He protested and declared that it was for his grandfather. I
was truly thankful I had seen it and disposed of it before M. arrived,
for she had never been to this part of the world before and would
have felt terrified to see the coachman so provided.

When we got home Willing's mother came and repeated the tale
about the whiskey having been got for her father, and I gave her the
bottle. I know this little tale is pure fiction, for her father never
drinks, is a model old man, and I happen to know a piece of inside
history about Willing, which he confided to Gerty, and she passed it
on to Chloe, who in turn confided it to me, when warning me that
my faith in Willing and his meek ways might be misplaced.

He told Gerty, who is his brother's fiancée, that he was "coa'tin',"


but that when he went to see the object of his affection he couldn't
say a word, but sat dumb before her, unless he drank a pint of
dispensary on the way to her house. Then he was all right and could
talk a-plenty. I called for him this evening and gave him a serious
talk.

"Then he could talk a-plenty."

I reminded him that when he was about five years old his father
had gone to Gregory to pay his tax, having his pocket full of money
from the sale of his crop. His poor mother walked the road all night
with the baby in her arms hoping for his return. He was an excellent
man, faithful to all his duties, a splendid worker, but he could not
resist "fire water."

When I heard in the morning that he had not returned, and the
other men who went with him had, I had Elihu get the pony carriage
and drive down the road until he found him and bring him home, as
the men said he had dropped asleep on the road and they could not
rouse him, so they came on and left him. It was a bitter night, one
of the three or four freezes we have during the winter, and I knew it
would go hard with him.
Elihu found him eight miles away, got help and put him in the
pony carriage, for Emanuel was a tall, heavy man, and drove rapidly
home; but life was extinct when he reached the poor wife. I had
sent beef tea and stimulant to be given him, but though Elihu found
him alive, he could not force anything down; he seemed unable to
swallow.

Lisbeth nearly went crazy; she had seven children to support by


her own labors. As time passed she quieted down and having her
house and firewood and two acres of land free of all rent and
owning a fine pair of oxen and a cow, she got on very comfortably
and brought up her children respectably.

When her only daughter, Aphrodite, married and her two oldest
sons went to "town" to work and were making a dollar a day, she
felt as though her troubles were over. But the same Devil's chain
gripped and held her eldest son Zebedee.

He was a splendid boatman and was as much at home in the


water as a duck. He owned a canoe and made an easy living, at the
same time satisfying his love of sport by taking strangers out
ducking. Many Northern people come to Gregory every winter for
that sport.

Last January and February we had several bitter spells of


weather with a prolonged freeze and snow. During one of these,
when ducks were especially plentiful, Zeb took a stranger out. Late
that afternoon they met another sportsman, paddled by a darky, and
the parties spoke and commented on the unusual cold; and Zeb
produced his bottle of dispensary, offering it to the other paddler,
while his sportsman also produced a flask and urged it upon the
second sportsman, who being near his home and its bright fire
declined it and suggested to Sportsman No. 1 that he should land
and not go on shooting, it was so cold.
No. 1, however, said he was all right, and pointing to his
overcoat on the seat said he had not even put that on yet. They
parted and Zeb and Sportsman No. 1 were never seen again alive.

They did not return to Gregory that night, nor the next. Then
search was made, and the sportsman was found drowned and Zeb
was found frozen holding on to some puncheons on the edge of an
old canal. Near by was the boat, not capsized, and the things in it
except the overcoat.

It was surmised by those who knew the circumstances that the


sportsman, not being familiar with a dugout canoe, and not knowing
that it is dangerous to stand up in one, rose to put on his overcoat,
lost his balance and fell overboard, and Zeb plunged in to rescue
him, a thing he could easily have accomplished under ordinary
circumstances. But the spirits he had taken from time to time
paralyzed his great strength and skill in the water, and he not only
could not save the man but perished himself. He succeeded in
reaching the puncheons on the edge of the canal, but was unable to
pull himself out, and froze stiff there.

Of course I did not go into all these details to Willing, but made
him see that without that fatal bottle Zeb could have saved himself
and the man, and I tried to make him see that with such a family
history the only hope for him was to swear off absolutely. He
seemed much impressed and thanked me for my "chastisement," as
they call any solemn counsel and admonition, and promised to heed
it.

The chicks are very lively and eat bread crumbs and oatmeal
very heartily. I have enclosed a space in the garden of fifty feet in
circumference, with a netted wire fence six feet high, which I will
keep locked, and I hope to defy hawks, foxes, and bipeds as well.
Chloe is perfectly devoted to the chicks and feeds them with
enthusiasm every two hours.

Chloe is devoted to the chicks—feeds


them every two hours.

I am having much trouble at Casa Bianca. The hands continue to


resent my having given the keys to Nat, and they will not take
orders from him. They will not bind themselves either to rent any
certain amount of land, but sulk steadily.
I knew that the loss of my good foreman Marcus was
irremediable, and when I met him in "town" the other day he told
me he was perfectly wretched; that he missed the country so. Of
course it must be so at first.

Instead of using his really excellent powers of control and


organization, he is hauling wood for a living during the week and
preaching on Sunday; but his wife is perfectly happy in the high
social life. It is the old, old tragedy of Eve and her misguided
ambitions—the world, the flesh, and his satanic majesty. The apple
pleased her eye; she longed to taste it, and then the subtle whisper
came: "And it will make thee wise."

Marcus was making a handsome income; had a position of trust


and responsibility, where all his faculties were in use during the
week; and on Sundays he, no doubt, preached good, simple, useful
sermons to his congregation of laborers, for he came fresh from his
struggle with the earth and its realities. But to his wife came that
desire for social eminence; to wear silk frock and shine, and she
tugged and tugged until he consented to her going.

He remained a year alone on the plantation and then came the


inevitable. He followed, and now all the dignity of his life and
character has gone, and he is struggling to make himself contented
with what is supposed to be a higher station; that is, he takes orders
from no one. He will get accustomed to it after a time, but his
powers will shrink away, unused, and without responsibility his
character will crumble.

When he began as my foreman,[2] about fifteen years ago, his


writing was illegible, his figures hopeless. Steadily, patiently, I have
corrected his mistakes, looking over and deciphering his weekly
accounts and copying them down in my book before him so that he
could see how they should look. Now he writes a readable, nice
letter and any one could examine his accounts, and he knows and
realizes all this and knows that his standards have all grown and
risen more even than his knowledge.

Meantime I will have to give up altogether planting on wages,


and it looks as though there will be very little land rented. If I had
money of my own I would hire a good overseer and plant 100 acres
on wages and not rent any land to these recalcitrant hands, but it
would be madness to put a mortgage on the place and borrow
money at 8 per cent while rice is selling at 40 cents a bushel.

So I will simply remain passive and let the hands who wish to
rent have the land and seed, but explain that I cannot pay out any
money for extra work. I feel sure that some day rice will rise in price,
but every one seems to think differently, and all the planters are
either giving up entirely or diminishing their acreage very much and
turning to upland crops.

So far I have only forty acres of rice land rented, and I feel very
blue about the future. Then, again, my sheep and cattle at Casa
Bianca, which have been so remunerative to me all these years, are
giving me trouble now.

A friend and neighbor, who has been heretofore a confirmed rice


planter, and never planted an acre of corn, has become disgusted
with rice and enclosed a large body of land which has been thrown
out for years, and is going to plant corn and cotton. This land
touches mine, and my animals have had the run of it. The fence
which has been put up is neither "horse high, bull strong, nor pig
tight," and my cattle do not regard it at all, though it is a very nice
looking, comme il faut wire fence, and I will have to sell my cattle, I
fear, and confine the sheep in a limited pasture.

Ruth, my brag cow, who has given me fifteen fine calves, and
Rubin, my picture bull, just light over that neat fence as though it
did not exist, and the humble sheep go down on their knees and
creep under it, and I lie awake at night and wonder what I am to do
between my love for my creatures and my love for my neighbor.
CHAPTER V
Easter Sunday, May 1.

A beautiful, bright Easter. All nature seems to rejoice with man in


this great day of triumph over death.

Our little chapel, Prince Frederick's Pee Dee, is beautifully


wreathed with wild flowers and vines, the work of three young girls,
sisters, who, having but three days' holiday from their school
teaching, devoted one of them to this thank offering and labor of
love. We are all touched and softened by this act of devotion, and
the blessing of the day seems upon every one.

Prince Frederick's Pee Dee.


May 2.

Had a terrible shock to-day. I took M. to see the alfalfa field, and
there was not a leaf of anything in the five acres! Those two nights
of ice must have caught the alfalfa in its one tender stage, for all the
books say that after it is six inches high it will stand any amount of
cold. I am stunned, it is such an unexpected blow.

Having been desperately busy, and knowing that my fence was


perfectly secure, I have not been to look at the alfalfa since the
seventeenth, when it was fine, and now all the money I have spent
on it might as well have been thrown away, so far as any hope of
return goes—I fenced in that field of thirty acres with American
fence wire, forty inches high, and two strands of barbed wire on top,
hoping gradually to get it all in alfalfa by planting five acres every
year. I have five acres of fine oats in it now, but that brings in no
money, only feeds my horses.

I had to go for a long walk alone to steady myself, so as not to


break down entirely.
Cherokee, May 3.

The hands from Casa Bianca came this morning to get seed rice.
I was just starting to drive M. to the train, but as it is very important
to get the rice planted as soon as possible I had to delay the
departure until to-morrow, for it was too late when I had finished
measuring out the rice to drive to Gregory in time for the 4: 30 train.
May 4.

Drove M. to the R. R. yesterday. I was afraid to take Willing,


knowing his weakness for the dispensary; so drove her in the
buckboard. On the way I took her into Woodstock, my brother's
place, that she might see its beauty, and then when we reached
Gregory I took her to see the old church, Prince George Winyah, and
its churchyard, where my parents rest. The church was built of brick
imported from the old country, and it is one of the oldest in the land.
The churchyard is beautiful with its moss hung oaks and cedars, and
one feels that it is truly God's acre. We lingered there so long that
there was a risk of missing the train, which would have been most
inconvenient to both guest and hostess. By driving rapidly, however,
we reached the station in time.

As it was too late for me to take the long drive home alone I
went into Woodstock and spent the night with my brother. This
morning after breakfast I drove to Casa Bianca, which is halfway
between Woodstock and Cherokee. There I had a good many things
to see after, and it was late afternoon before I got through and
finally started for home.

Prince George Winyah.


I had been so much engrossed with my work trying to establish
a better state of feeling between the hands and Nat that I had not
noticed that the clouds had gathered heavily and that everything
indicated a storm. When I felt the gusts of wind which tore at the
umbrella so fiercely that I had to put it down in spite of a drizzling
rain, and saw the forked lightning which shot incessantly from the
clouds, and thought of the eight miles of lonely road ahead of me, I
realized that I would have to bring forward all my faith and
philosophy for the next hour. From being by nature a great coward I
had become very courageous, and I have often caught myself saying
there were only two things in the world I was afraid of, a cow and a
drunken man, and I could not help calling this to mind now and
wondering how I would stand the present ordeal. Romola, who is
generally very quiet, snorted and showed every sign of fear, but I did
not give her time to give way to her feelings, but used the whip
freely, a thing I very rarely do, to make her understand that she
must travel. She responded nobly and we sped along.

The clouds made it much darker than it should have been, for
the sun had only just gone down. I have never seen such vivid
lightning nor heard such claps of thunder, and at each Romola
darted out of the road as though the thick bushes could protect her.
Not a human being was to be seen the whole way, and when I got
to the avenue gate, which was shut, I had, of course, to get out to
open it, and I felt sure Romola would fly home and leave me; but I
did her an injustice. She waited, with every sign of impatience, long
enough for me with great speed to get in, and then dashed on until
we got to the darkest spot in the avenue, where the live oaks lap
together overhead. A fearful flash of lightning came, followed
instantly by a terrific peal of thunder, and she stopped short. I felt
sure she had been struck, and she seemed to share the impression,
but in a moment she went on and we were soon at home.
I was so excited that I was in a perfect gale of spirits, which
quite upset my good Chloe, who had worked herself up to a
wretched state of anxiety about me, miserable that I was out in that
terrible storm alone; and she was hurt and disapproving of my
attitude, especially as the first thing I did was to insist that Gerty
and herself should take in my best rug, which had been hung on the
piazza to air. Their terror had been so great that they had left it out
in the rain—such a panic had seized them that they were very
reluctant to venture out on the piazza. They had the house shut up
without a breath of air, that being their idea of safety. Of course, I
was drenched and had to change all my things, and after two hours
I sent word to Willing that he might safely feed the mare, I having
told him to rub her perfectly dry, but not to feed her till I sent him
word. What was my dismay to find he had not rubbed her at all—
said he was afraid to stay in the stable, so he had turned her loose
in the stable yard and gone into the kitchen, leaving her exposed to
the pouring rain! Of course she will be foundered, for she was very
hot.
Sunday, May 8.

Drove Ruth to church and met some one just from Gregory on
the way, who told me a most terrible thing. Mrs. R., one of the
loveliest women in our community, was struck by lightning during
the storm last evening. She had always had a great terror of
lightning, though in every other respect she was a fearless woman,
so that her family always gathered round her during a storm and
tried as much as possible to shut out the sight and sound. On this
occasion her husband and daughter were sitting one on each side of
her on an old-fashioned mahogany sofa, she with her handkerchief
thrown over her face. When the fatal flash came the husband and
daughter were thrown forward to the floor and were stunned; as
soon as they recovered consciousness they turned to reassure the
mother as to their not being seriously hurt. She was still sitting
straight up on the sofa with the handkerchief over her face; they
lifted the handkerchief as they received no answer and found life
extinct. It was a translation really for her, as she probably felt
nothing; there was only one small spot at the back of the neck. She
was a woman rarely gifted, with beauty of face and form, as well as
of soul; she was one upon whom every one rested who came in
contact with her; she gave of her strength to all who needed it, for
her supply was unlimited, coming direct from the great source of all
power. I wonder if terror of lightning was a premonition which had
been with, her always from her childhood? Her death is a great loss
to our county, and to her family a calamity indeed.
May 9.

Very busy arranging things so that I can leave for my annual


visit to Washington. It is harder than ever, for Jim not being here to
leave in charge of the horses I feel very anxious. However, I have
done my best and will leave to-morrow. The incubator is in full swing
and Chloe and Gerty have learned how to manage the heat between
them. The chicks are due to hatch on the 14th, and I have left most
accurate written directions for each day which Gerty is to read aloud
to Chloe as the day comes, for toward the end the heat must be
raised. The first family of sixty-seven are growing apace; only one
has died and that was smothered by the others before I found out
that I must put them under the hover every night or they will cluster
about the thermometer and climb on top of each other until the
ones underneath are smothered if help does not come. It is the
funniest thing to see their devotion to the thermometer. They peck it
off of the nail on which it hangs, so that as soon as I learned to
know the proper heat for the brooder by touching the metal cylinder
under the hover, I took the thermometer out entirely, and as soon as
it was gone they went under the hover of their own accord. They
seemed to feel that the mercury was a living presence, I suppose,
because it moved up and down in the tube.
I am leaving Willing to run one cultivator, with Mollie and Gibbie
to run the other with a fine ox I have just bought. I heard that
Gibbie had made his plans to "go to town" to work, leaving his
young wife and child, and I racked my brain for something that
would interest him at home and divert his thoughts from that plan;
for if once a young negro leaves his wife and children to go away to
work he is very apt to stay away permanently, and I should be sorry
for Gibbie to do that. One day I called him and said: "Gibbie, I wish
to try an experiment and put you in charge of it, and I am going
away for a month. You know, in this country no one ever thinks of
ploughing a single ox; they can't do anything without a yoke of
oxen; but in the up country it is not so. On my way to the mountains
I see from the car windows people running their ploughs with a
single ox. Now I want you to take entire charge of Paul—no one else
is to use him—and I want you to put him in the cultivator and run it
through the corn day by day until you finish that, and then through
the cotton, and then start through the corn again; but be careful of
Paul and do not let him get galled, and feed him well."

Gibbie was as proud as though he had been made Viceroy of


India and his plan of deserting vanished.
May 26.

Washington. Spent the afternoon at the Agricultural Department,


where I met with much courtesy as well as information. I went
specially to inquire as to the practicability of the cultivation of the
orris root on our rice field lands. The orris of commerce is the root of
the iris, which grows luxuriantly in our low country. In the latter part
of March and during the month of April every swampy low spot, as
one drives along the road, is beautiful with the dark purple or blue
and the light purple and the white iris, or flag. My desire was to find
out if these species of iris had the perfumed root, for if they have we
could cultivate it in the rice fields with great success.

You might also like