Spring in Action Page: 2 Copyright Page: 3 From the fifth edition of Spring in Action by Craig Walls Page: 4 brief contents Page: 5 contents Page: 6 front matter Page: 7 preface Page: 7 acknowledgments Page: 7 about this book Page: 7 Who should read this book Page: 7 How this book is organized: A roadmap Page: 7 About the code Page: 8 Book forum Page: 8 Other online resources Page: 8 about the author Page: 9 about the cover illustration Page: 9 Part 1. Foundational Spring Page: 10 1 Getting started with Spring Page: 11 1.1 What is Spring? Page: 11 1.2 Initializing a Spring application Page: 12 1.2.1 Initializing a Spring project with Spring Tool Suite Page: 12 1.2.2 Examining the Spring project structure Page: 13 1.3 Writing a Spring application Page: 15 1.3.1 Handling web requests Page: 16 1.3.2 Defining the view Page: 16 1.3.3 Testing the controller Page: 16 1.3.4 Building and running the application Page: 17 1.3.5 Getting to know Spring Boot DevTools Page: 18 1.3.6 Let’s review Page: 19 1.4 Surveying the Spring landscape Page: 19 1.4.1 The core Spring Framework Page: 19 1.4.2 Spring Boot Page: 19 1.4.3 Spring Data Page: 20 1.4.4 Spring Security Page: 20 1.4.5 Spring Integration and Spring Batch Page: 20 1.4.6 Spring Cloud Page: 20 1.4.7 Spring Native Page: 20 Summary Page: 20 2 Developing web applications Page: 21 2.1 Displaying information Page: 21 2.1.1 Establishing the domain Page: 21 2.1.2 Creating a controller class Page: 22 2.1.3 Designing the view Page: 24 2.2 Processing form submission Page: 25 2.3 Validating form input Page: 28 2.3.1 Declaring validation rules Page: 28 2.3.2 Performing validation at form binding Page: 29 2.3.3 Displaying validation errors Page: 29 2.4 Working with view controllers Page: 30 2.5 Choosing a view template library Page: 31 2.5.1 Caching templates Page: 31 Summary Page: 32 3 Working with data Page: 33 3.1 Reading and writing data with JDBC Page: 33 3.1.1 Adapting the domain for persistence Page: 34 3.1.2 Working with JdbcTemplate Page: 34 3.1.3 Defining a schema and preloading data Page: 36 3.1.4 Inserting data Page: 37 3.2 Working with Spring Data JDBC Page: 38 3.2.1 Adding Spring Data JDBC to the build Page: 39 3.2.2 Defining repository interfaces Page: 39 3.2.3 Annotating the domain for persistence Page: 39 3.2.4 Preloading data with CommandLineRunner Page: 40 3.3 Persisting data with Spring Data JPA Page: 41 3.3.1 Adding Spring Data JPA to the project Page: 41 3.3.2 Annotating the domain as entities Page: 41 3.3.3 Declaring JPA repositories Page: 42 3.3.4 Customizing repositories Page: 43 Summary Page: 44 4 Working with nonrelational data Page: 45 4.1 Working with Cassandra repositories Page: 45 4.1.1 Enabling Spring Data Cassandra Page: 45 4.1.2 Understanding Cassandra data modeling Page: 46 4.1.3 Mapping domain types for Cassandra persistence Page: 47 4.1.4 Writing Cassandra repositories Page: 49 4.2 Writing MongoDB repositories Page: 49 4.2.1 Enabling Spring Data MongoDB Page: 49 4.2.2 Mapping domain types to documents Page: 50 4.2.3 Writing MongoDB repository interfaces Page: 51 Summary Page: 51 5 Securing Spring Page: 52 5.1 Enabling Spring Security Page: 52 5.2 Configuring authentication Page: 52 5.2.1 In-memory user details service Page: 53 5.2.2 Customizing user authentication Page: 53 5.3 Securing web requests Page: 55 5.3.1 Securing requests Page: 56 5.3.2 Creating a custom login page Page: 57 5.3.3 Enabling third-party authentication Page: 58 5.3.4 Preventing cross-site request forgery Page: 59 5.4 Applying method-level security Page: 59 5.5 Knowing your user Page: 60 Summary Page: 61 6 Working with configuration properties Page: 62 6.1 Fine-tuning autoconfiguration Page: 62 6.1.1 Understanding Spring’s environment abstraction Page: 62 6.1.2 Configuring a data source Page: 63 6.1.3 Configuring the embedded server Page: 63 6.1.4 Configuring logging Page: 64 6.1.5 Using special property values Page: 64 6.2 Creating your own configuration properties Page: 65 6.2.1 Defining configuration property holders Page: 65 6.2.2 Declaring configuration property metadata Page: 66 6.3 Configuring with profiles Page: 67 6.3.1 Defining profile-specific properties Page: 67 6.3.2 Activating profiles Page: 68 6.3.3 Conditionally creating beans with profiles Page: 68 Summary Page: 69 Part 2. Integrated Spring Page: 70 7 Creating REST services Page: 71 7.1 Writing RESTful controllers Page: 71 7.1.1 Retrieving data from the server Page: 71 7.1.2 Sending data to the server Page: 73 7.1.3 Updating data on the server Page: 74 7.1.4 Deleting data from the server Page: 75 7.2 Enabling data-backed services Page: 75 7.2.1 Adjusting resource paths and relation names Page: 76 7.2.2 Paging and sorting Page: 77 7.3 Consuming REST services Page: 77 7.3.1 GETting resources Page: 78 7.3.2 PUTting resources Page: 79 7.3.3 DELETEing resources Page: 79 7.3.4 POSTing resource data Page: 79 Summary Page: 80 8 Securing REST Page: 81 8.1 Introducing OAuth 2 Page: 81 8.2 Creating an authorization server Page: 83 8.3 Securing an API with a resource server Page: 86 8.4 Developing the client Page: 87 Summary Page: 89 9 Sending messages asynchronously Page: 90 9.1 Sending messages with JMS Page: 90 9.1.1 Setting up JMS Page: 90 9.1.2 Sending messages with JmsTemplate Page: 91 9.1.3 Receiving JMS messages Page: 94 9.2 Working with RabbitMQ and AMQP Page: 96 9.2.1 Adding RabbitMQ to Spring Page: 96 9.2.2 Sending messages with RabbitTemplate Page: 97 9.2.3 Receiving messages from RabbitMQ Page: 99 9.3 Messaging with Kafka Page: 100 9.3.1 Setting up Spring for Kafka messaging Page: 101 9.3.2 Sending messages with KafkaTemplate Page: 101 9.3.3 Writing Kafka listeners Page: 102 Summary Page: 102 10 Integrating Spring Page: 104 10.1 Declaring a simple integration flow Page: 104 10.1.1 Defining integration flows with XML Page: 105 10.1.2 Configuring integration flows in Java Page: 105 10.1.3 Using Spring Integration’s DSL configuration Page: 106 10.2 Surveying the Spring Integration landscape Page: 107 10.2.1 Message channels Page: 107 10.2.2 Filters Page: 108 10.2.3 Transformers Page: 108 10.2.4 Routers Page: 109 10.2.5 Splitters Page: 109 10.2.6 Service activators Page: 110 10.2.7 Gateways Page: 111 10.2.8 Channel adapters Page: 111 10.2.9 Endpoint modules Page: 112 10.3 Creating an email integration flow Page: 113 Summary Page: 116 Part 3. Reactive Spring Page: 117 11 Introducing Reactor Page: 118 11.1 Understanding reactive programming Page: 118 11.1.1 Defining Reactive Streams Page: 119 11.2 Getting started with Reactor Page: 120 11.2.1 Diagramming reactive flows Page: 120 11.2.2 Adding Reactor dependencies Page: 120 11.3 Applying common reactive operations Page: 121 11.3.1 Creating reactive types Page: 121 11.3.2 Combining reactive types Page: 122 11.3.3 Transforming and filtering reactive streams Page: 123 11.3.4 Performing logic operations on reactive types Page: 127 Summary Page: 127 12 Developing reactive APIs Page: 128 12.1 Working with Spring WebFlux Page: 128 12.1.1 Introducing Spring WebFlux Page: 128 12.1.2 Writing reactive controllers Page: 129 12.2 Defining functional request handlers Page: 130 12.3 Testing reactive controllers Page: 132 12.3.1 Testing GET requests Page: 132 12.3.2 Testing POST requests Page: 133 12.3.3 Testing with a live server Page: 134 12.4 Consuming REST APIs reactively Page: 134 12.4.1 GETting resources Page: 135 12.4.2 Sending resources Page: 135 12.4.3 Deleting resources Page: 136 12.4.4 Handling errors Page: 136 12.4.5 Exchanging requests Page: 137 12.5 Securing reactive web APIs Page: 137 12.5.1 Configuring reactive web security Page: 137 12.5.2 Configuring a reactive user details service Page: 138 Summary Page: 139 13 Persisting data reactively Page: 140 13.1 Working with R2DBC Page: 140 13.1.1 Defining domain entities for R2DBC Page: 140 13.1.2 Defining reactive repositories Page: 142 13.1.3 Testing R2DBC repositories Page: 142 13.1.4 Defining an OrderRepository aggregate root service Page: 143 13.2 Persisting document data reactively with MongoDB Page: 146 13.2.1 Defining domain document types Page: 146 13.2.2 Defining reactive MongoDB repositories Page: 147 13.2.3 Testing reactive MongoDB repositories Page: 147 13.3 Reactively persisting data in Cassandra Page: 148 13.3.1 Defining domain classes for Cassandra persistence Page: 148 13.3.2 Creating reactive Cassandra repositories Page: 149 13.3.3 Testing reactive Cassandra repositories Page: 150 Summary Page: 150 14 Working with RSocket Page: 151 14.1 Introducing RSocket Page: 151 14.2 Creating a simple RSocket server and client Page: 151 14.2.1 Working with request-response Page: 152 14.2.2 Handling request-stream messaging Page: 153 14.2.3 Sending fire-and-forget messages Page: 154 14.2.4 Sending messages bidirectionally Page: 154 14.3 Transporting RSocket over WebSocket Page: 155 Summary Page: 156 Part 4. Deployed Spring Page: 157 15 Working with Spring Boot Actuator Page: 158 15.1 Introducing Actuator Page: 158 15.1.1 Configuring Actuator’s base path Page: 159 15.1.2 Enabling and disabling Actuator endpoints Page: 159 15.2 Consuming Actuator endpoints Page: 159 15.2.1 Fetching essential application information Page: 159 15.2.2 Viewing configuration details Page: 161 15.2.3 Viewing application activity Page: 164 15.2.4 Tapping runtime metrics Page: 164 15.3 Customizing Actuator Page: 166 15.3.1 Contributing information to the /info endpoint Page: 166 15.3.2 Defining custom health indicators Page: 167 15.3.3 Registering custom metrics Page: 168 15.3.4 Creating custom endpoints Page: 168 15.4 Securing Actuator Page: 169 Summary Page: 170 16 Administering Spring Page: 171 16.1 Using Spring Boot Admin Page: 171 16.1.1 Creating an Admin server Page: 171 16.1.2 Registering Admin clients Page: 171 16.2 Exploring the Admin server Page: 172 16.2.1 Viewing general application health and information Page: 172 16.2.2 Watching key metrics Page: 172 16.2.3 Examining environment properties Page: 172 16.2.4 Viewing and setting logging levels Page: 172 16.3 Securing the Admin server Page: 173 16.3.1 Enabling login in the Admin server Page: 173 16.3.2 Authenticating with the Actuator Page: 173 Summary Page: 173 17 Monitoring Spring with JMX Page: 174 17.1 Working with Actuator MBeans Page: 174 17.2 Creating your own MBeans Page: 174 17.3 Sending notifications Page: 175 Summary Page: 175 18 Deploying Spring Page: 176 18.1 Weighing deployment options Page: 176 18.2 Building executable JAR files Page: 176 18.3 Building container images Page: 177 18.3.1 Deploying to Kubernetes Page: 178 18.3.2 Enabling graceful shutdown Page: 179 18.3.3 Working with application liveness and readiness Page: 179 18.4 Building and deploying WAR files Page: 181 18.5 The end is where we begin Page: 181 Summary Page: 182 Appendix. Bootstrapping Spring applications Page: 183 A.1 Initializing a project with Spring Tool Suite Page: 183 A.2 Initializing a project with IntelliJ IDEA Page: 183 A.3 Initializing a project with NetBeans Page: 183 A.4 Initializing a project at start.spring.io Page: 184 A.5 Initializing a project from the command line Page: 184 curl and the Initializr API Page: 185 Spring Boot command-line interface Page: 185 A.6 Building and running projects Page: 186 index Page: 187
Description: