Spring Boot 3 and Spring Framework 6
2023945877, 9781493224753, 9781493224760, 9781493224777
Say goodbye to dependencies, bogged-down code, and inflexibility! With the Spring framework and Spring Boot, you’ll pain
157
46
23MB
English
Pages 934
Year 2024
Report DMCA / Copyright
DOWNLOAD EPUB FILE
Table of contents :
Notes on Usage
Table of Contents
Preface
What Is Spring Boot?
Prior Knowledge and Target Group
Date4u Demo Application, Tasks, and Solutions
Chapter Organization
The * Sections
Which Java Version Is Used in the Book?
Required Software
Development Environment
Conventions
Program Listings
Download and Online Information
About the Author
Feedback
1 Introduction
1.1 History of Spring Framework and Your First Spring Project
1.1.1 Tasks of Java Platform, Standard Edition
1.1.2 Enterprise Requirements
1.1.3 Development of Java Enterprise Frameworks
1.1.4 Rod Johnson Develops a Framework
1.1.5 Spring Framework: Many Configurations Are Required
1.2 Spring Boot
1.2.1 Spring Boot Versions
1.2.2 Support Period
1.2.3 Alternatives to Spring
1.2.4 Setting Up a Spring Boot Project
1.2.5 Building Spring Projects in Development Environments
1.3 Spring Boot Project: Dependencies and Starter
1.3.1 Project Object Model with Parent Project Object Model
1.3.2 Dependencies as Imports
1.3.3 Milestones and the Snapshots Repository
1.3.4 Configuring Annotation Processors
1.3.5 Starter: Dependencies of the Spring Initializr
1.4 Getting Started with Configurations and Logging
1.4.1 Turning Off the Banner
1.4.2 Logging API and Simple Logging Facade for Java
1.5 Summary
2 Containers for Spring-Managed Beans
2.1 Spring Container
2.1.1 Start Container
2.1.2 Instantiate SpringApplication
2.1.3 SpringApplicationBuilder *
2.1.4 What main(…) Does and Doesn’t Do
2.1.5 The run(…) Method Returns ConfigurableApplicationContext
2.1.6 Context Methods
2.2 Package Structure of the Date4u Application
2.3 Pick Up Spring-Managed Beans through Classpath Scanning
2.3.1 Fill Container with Beans
2.3.2 @Component
2.3.3 @Repository, @Service, @Controller
2.3.4 Control Classpath Scanning More Precisely with @ComponentScan *
2.4 Interactive Applications with the Spring Shell
2.4.1 Include a Spring Shell Dependency
2.4.2 First Interactive Application
2.4.3 Write Shell Component: @ShellComponent, @ShellMethod
2.5 Injecting Dependencies
2.5.1 Build Object Graphs
2.5.2 Inversion of Control and Dependency Injection
2.5.3 Injection Types
2.5.4 PhotoService and PhotoCommands
2.5.5 Multiple Dependencies
2.5.6 Behavior in Case of a Missing Component
2.5.7 Optional Dependency
2.5.8 Cyclic Dependencies *
2.5.9 Inject Other Things
2.6 Configuration Classes and Factory Methods
2.6.1 What @Component Can’t Do
2.6.2 @Configuration and @Bean
2.6.3 Parameter Injection of an @Bean Method
2.6.4 @Configuration Bean and Lite Bean
2.6.5 InjectionPoint *
2.6.6 Static @Bean Methods *
2.6.7 @Import and @ImportSelector *
2.7 Abstraction and Qualifications
2.7.1 Bean Name and Alias
2.7.2 AwtBicubicThumbnail for Thumbnails
2.7.3 Basic Types
2.7.4 ObjectProvider
2.7.5 @Order and @AutoConfigurationOrder *
2.7.6 Behavior in Selected Inheritance Relationships *
2.8 Beans Lifecycle
2.8.1 @DependsOn
2.8.2 Delayed Initialization (Lazy Initialization)
2.8.3 Bean Initialization Traditional
2.8.4 InitializingBean and DisposableBean *
2.8.5 Inheritance of the Lifecycle Methods
2.8.6 *Aware Interfaces *
2.8.7 BeanPostProcessor *
2.8.8 Register Spring-Managed Beans Somewhere Else
2.8.9 Hierarchical Contexts *
2.8.10 Singleton and Prototype Stateless or Stateful
2.9 Annotations from JSR 330, Dependency Injection for Java *
2.9.1 Dependency for the JSR 330 Standard Annotation
2.9.2 Map JSR 330 Annotations to Spring
2.10 Auto-Configuration
2.10.1 @Conditional and Condition
2.10.2 If, Then: @ConditionalOn*
2.10.3 Turn on Spring Debug Logging
2.10.4 Controlling Auto-Configurations Individually *
2.11 Spring Expression Language
2.11.1 ExpressionParser
2.11.2 SpEL in the Spring (Boot) API
2.12 Summary
3 Selected Modules of the Spring Framework
3.1 Helper Classes in Spring Framework
3.1.1 Components of org.springframework
3.2 External Configuration and the Environment
3.2.1 Code and External Configuration
3.2.2 Environment
3.2.3 Inject Values with @Value
3.2.4 Get Environment Assignments via @Value and ${…}
3.2.5 @Value and Default Values
3.2.6 Access to Configurations
3.2.7 Nested/Hierarchical Properties
3.2.8 Map Special Data Types
3.2.9 Relaxed Bindings
3.2.10 Property Sources
3.2.11 Define Spring Profiles
3.2.12 Activate Profiles
3.2.13 Spring-Managed Beans Depending on Profile
3.3 At the Beginning and End
3.3.1 CommandLineRunner and ApplicationRunner
3.3.2 At the End of the Application
3.3.3 Exit Java Programs with Exit Code *
3.4 Event Handling
3.4.1 Participating Objects
3.4.2 Context Events
3.4.3 ApplicationListener
3.4.4 @EventListener
3.4.5 Methods of the Event Classes
3.4.6 Write Event Classes and React to the Events
3.4.7 An Event Bus of Type ApplicationEventPublisher
3.4.8 Generic Events Using the PayloadApplicationEvent Example
3.4.9 Event Transformations
3.4.10 Sequences by @Order
3.4.11 Filter Events by Conditions
3.4.12 Synchronous and Asynchronous Events
3.4.13 ApplicationEventMulticaster *
3.4.14 Send Events via ApplicationContext
3.4.15 Attach Listener to SpringApplication *
3.4.16 Listener in spring.factories *
3.5 Resource Abstraction with Resource
3.5.1 InputStreamSource and Resource
3.5.2 Load Resources
3.5.3 Inject Resources via @Value
3.6 Type Conversion with ConversionService
3.6.1 ConversionService
3.6.2 DefaultConversionService and ApplicationConversionService
3.6.3 ConversionService as Spring-Managed Bean
3.6.4 Register Your Own Converters with the ConverterRegistry
3.6.5 Printer and Parser
3.6.6 FormatterRegistry
3.6.7 DataBinder
3.7 Internationalization *
3.7.1 Possibilities for Internationalization with Java SE
3.7.2 MessageSource under Subtypes
3.8 Test-Driven Development with Spring Boot
3.8.1 Test Related Entries from Spring Initializr
3.8.2 Annotation @Test
3.8.3 Test Case for the FileSystem Class
3.8.4 Test Multitier Applications, Exchange Objects
3.8.5 Mocking Framework Mockito
3.8.6 @InjectMocks
3.8.7 Verify Behavior
3.8.8 Testing with ReflectionTestUtils
3.8.9 With or Without Spring Support
3.8.10 Test Properties
3.8.11 @TestPropertySource
3.8.12 @ActiveProfiles
3.8.13 Appoint Deputy
3.8.14 @DirtiesContext
3.9 Testing Slices Using a JSON Example *
3.9.1 JSON
3.9.2 Jackson
3.9.3 Write a Java Object in JSON
3.9.4 Testing JSON Mappings: @JsonTest
3.9.5 Mapping with @JsonComponent
3.10 Scheduling *
3.10.1 Scheduling Annotations and @EnableScheduling
3.10.2 @Scheduled
3.10.3 Disadvantages of @Scheduled and Alternatives
3.11 Types from org.springframework.*.[lang|util]
3.11.1 org.springframework.lang.*Null* Annotations
3.11.2 Package org.springframework.util
3.11.3 Package org.springframework.data.util
3.12 Summary
4 Selected Proxies
4.1 Proxy Pattern
4.1.1 Proxy Deployment in Spring
4.1.2 Dynamically Generate Proxies
4.2 Caching
4.2.1 Optimization through Caching
4.2.2 Caching in Spring
4.2.3 Component with the @Cacheable Method
4.2.4 Use @Cacheable Proxy
4.2.5 @Cacheable + Condition
4.2.6 @Cacheable + Unless
4.2.7 @CachePut
4.2.8 @CacheEvict
4.2.9 Specify Your Own Key Generators
4.2.10 @CacheConfig
4.2.11 Cache Implementations
4.2.12 Caching with Caffeine
4.2.13 Disable the Caching in the Test
4.3 Asynchronous Calls
4.3.1 @EnableAsync and @Async Methods
4.3.2 Example with @Async
4.3.3 The CompletableFuture Return Type
4.4 TaskExecutor *
4.4.1 TaskExecutor Implementations
4.4.2 Set Executor and Handle Exceptions
4.5 Spring and Bean Validation
4.5.1 Parameter Checks
4.5.2 Jakarta Bean Validation (JSR 303)
4.5.3 Dependency on Spring Boot Starter Validation
4.5.4 Photo with Jakarta Bean Validation Annotations
4.5.5 Inject and Test a Validator
4.5.6 Spring and the Bean Validation Annotations
4.5.7 Bean Validation Annotations to Methods
4.5.8 Validation Everywhere Using a Configuration Example
4.5.9 Test Validation *
4.6 Spring Retry *
4.6.1 Spring Retry Project
4.6.2 @Retryable
4.6.3 Fallback with @Recover
4.6.4 RetryTemplate
4.7 Summary
5 Connecting to Relational Databases
5.1 Set Up an H2 Database
5.1.1 Brief Introduction to the H2 Database
5.1.2 Install and Launch H2
5.1.3 Connect to the Database via the H2 Console
5.1.4 Date4u Database Schema
5.2 Realize Database Accesses with Spring
5.2.1 Spring Helper
5.3 Spring Boot Starter JDBC
5.3.1 Include the JDBC Starter in the Project Object Model
5.3.2 Provide JDBC Connection Data
5.3.3 Inject DataSource or JdbcTemplate
5.3.4 Connection Pooling
5.3.5 Log JDBC Accesses
5.3.6 JDBC org.springframework.jdbc Package and Its Subpackages
5.3.7 DataAccessException
5.3.8 Auto-Configuration for DataSource *
5.3.9 Addressing Multiple Databases
5.3.10 DataSourceUtils *
5.4 JdbcTemplate
5.4.1 Execute Any SQL: execute(…)
5.4.2 SQL Updates: update(…)
5.4.3 Query Individual Values: queryForObject(…)
5.4.4 Define a Placeholder for a PreparedStatement
5.4.5 Query Whole Row: queryForMap(…)
5.4.6 Query Multiple Rows with One Element: queryForList(…)
5.4.7 Read Multiple Rows and Columns: queryForList(…)
5.5 Data Types for Mapping to Results
5.5.1 RowMapper
5.5.2 RowCallbackHandler
5.5.3 ResultSetExtractor
5.6 NamedParameterJdbcTemplate
5.6.1 Type Relationships of *JdbcTemplate
5.6.2 Methods of the NamedParameterJdbcTemplate
5.6.3 Pass Values of NamedParameterJdbcTemplate through a Map
5.6.4 SqlParameterSource
5.6.5 Access to Underlying Objects *
5.7 Batch Operations *
5.7.1 Batch Methods for JdbcTemplate
5.7.2 BatchPreparedStatementSetter
5.7.3 Batch Methods at NamedParameterJdbcTemplate
5.7.4 SqlParameterSourceUtils
5.7.5 Configuration Properties
5.8 BLOBs and CLOBs *
5.8.1 SqlLobValue
5.8.2 LobHandler and DefaultLobHandler
5.8.3 Read LOBs via AbstractLobStreamingResultSetExtractor
5.9 Subpackage org.springframework.jdbc.core.simple *
5.9.1 SimpleJdbcInsert
5.10 Package org.springframework.jdbc.object *
5.10.1 MappingSqlQuery
5.11 Transactions
5.11.1 ACID Principle
5.11.2 Local or Global/Distributed Transactions
5.11.3 JDBC Transactions: Auto-Commit
5.11.4 PlatformTransactionManager
5.11.5 TransactionTemplate
5.11.6 @Transactional
5.12 Summary
6 Jakarta Persistence with Spring
6.1 World of Objects and Databases
6.1.1 Transient and Persistent
6.1.2 Mapping Objects to Tables
6.1.3 Java Libraries for O/R Mapping
6.2 Jakarta Persistence
6.2.1 Persistence Provider
6.2.2 Jakarta Persistence Provider and JDBC
6.2.3 Jakarta Persistence Coverage
6.3 Spring Data JPA
6.3.1 Include Spring Boot Starter Data JPA
6.3.2 Configurations
6.4 Jakarta Persistence Entity Bean
6.4.1 Develop an Entity Bean Class
6.5 Jakarta Persistence API
6.5.1 Getting the EntityManager from Spring
6.5.2 Search an Entity Bean by Its Key: find(…)
6.5.3 find(…) and getReference(…)
6.5.4 Query Options with the EntityManager
6.6 Jakarta Persistence Query Language (JPQL)
6.6.1 JPQL Example with SELECT and FROM
6.6.2 Build and Submit JPQL Queries with createQuery(…)
6.6.3 Conditions in WHERE
6.6.4 Parameterize JPQL Calls
6.6.5 JPQL Operators and Functions
6.6.6 Order Returns with ORDER BY
6.6.7 Projection on Scalar Values
6.6.8 Aggregate Functions
6.6.9 Projection on Multiple Values
6.6.10 Named Declarative Queries (Named Queries)
6.7 Call Database Functions and Send Native SQL Queries
6.7.1 Call Database Functions: FUNCTION(…)
6.7.2 Use createNativeQuery(…) via EntityManager
6.7.3 @NamedNativeQuery
6.7.4 @NamedNativeQuery with resultSetMapping
6.8 Write Access with the EntityManager in Transactions
6.8.1 Transactional Operations
6.8.2 persist(…)
6.8.3 EntityTransaction
6.8.4 PlatformTransactionManager with JpaTransactionManager
6.8.5 @Transactional
6.8.6 Save versus Update
6.8.7 remove(…)
6.8.8 Synchronization or Flush
6.8.9 Query with UPDATE and DELETE
6.9 Persistence Context and Other Transaction Controls
6.9.1 Jakarta Persistence API and Database Operations
6.9.2 States of an Entity Bean
6.10 Advanced ORM Metadata
6.10.1 Database-First and Code-First Approaches
6.10.2 Set the Table Name via @Table
6.10.3 Change the @Entity Name
6.10.4 Persistent Attributes
6.10.5 @Basic and @Transient
6.10.6 Column Description and @Column
6.10.7 Entity Bean Data Types
6.10.8 Map Data Types with AttributeConverter
6.10.9 Key Identification
6.10.10 Embedded Types
6.10.11 Entity Bean Inherits Properties from a Superclass
6.11 Relationships between Entities
6.11.1 Supported Associations and Relationship Types
6.11.2 1:1 Relationship
6.11.3 Bidirectional Relationships
6.11.4 1:n Relationship
6.11.5 n:m Relationships *
6.12 FetchType: Lazy and Eager Loading
6.12.1 Enumeration with FetchType
6.12.2 Hibernate Type: PersistentBag
6.12.3 1 + N Query Problem: Performance Anti-Pattern
6.13 Cascading
6.13.1 CascadeType Enumeration Type
6.13.2 Set CascadeType
6.13.3 cascade=REMOVE versus orphanRemoval=true
6.14 Repositories
6.14.1 Data Access Layer
6.14.2 Methods in the Repository
6.14.3 SimpleJpaRepository
6.15 Summary
7 Spring Data JPA
7.1 What Tasks Does Spring Data Perform?
7.1.1 For Which Systems Is Spring Data Available?
7.2 Spring Data Commons: CrudRepository
7.2.1 CrudRepository Type
7.2.2 Java Persistence API–Based Repositories
7.3 Subtypes of CrudRepository
7.3.1 ListCrudRepository
7.3.2 Technology-Specific [List]CrudRepository Subtypes
7.3.3 Selected Methods via Repository
7.4 Paging and Sorting with [List]PagingAndSortingRepository
7.4.1 JpaRepository: Subttype of ListPagingAndSortingRepository and ListCrudRepository
7.4.2 Sort Type
7.4.3 Sort.TypedSort
7.4.4 Pageable and PageRequest
7.4.5 Sort Paginated Pages
7.5 QueryByExampleExecutor *
7.5.1 Sample
7.5.2 QueryByExampleExecutor
7.5.3 Sample into the Example
7.5.4 Build ExampleMatcher
7.5.5 Ignore Properties
7.5.6 Set String Comparison Techniques
7.5.7 Set Individual Rules with GenericPropertyMatcher
7.5.8 PropertyValueTransformer
7.6 Formulate Your Own Queries with @Query
7.6.1 @Query Annotation
7.6.2 Modifying @Query Operations with @Modifying
7.6.3 Fill IN Parameter by Array/Varg/Collection
7.6.4 @Query with JPQL Projection
7.6.5 Sort and Pageable Parameters
7.6.6 Add New Query Methods
7.6.7 Queries with Spring Expression Language Expressions
7.6.8 Using the @NamedQuery of an Entity Bean
7.6.9 @Query Annotation with Native SQL
7.7 Stored Procedures *
7.7.1 Define a Stored Procedure in H2
7.7.2 Calling a Stored Procedure via a Native Query
7.7.3 Call a Stored Procedure with @Procedure
7.8 Derived Query Methods
7.8.1 Individual CRUD Operations via Method Names
7.8.2 Structure of the Derived Query Methods
7.8.3 Returns from Derived Query Methods
7.8.4 Asynchronous Query Methods
7.8.5 Streaming Query Methods
7.8.6 Advantages and Disadvantages of Derived Query Methods
7.9 Criteria API and JpaSpecificationExecutor
7.9.1 Criteria API
7.9.2 Functional Interface Specification
7.9.3 JpaSpecificationExecutor
7.9.4 Methods in JpaSpecificationExecutor
7.9.5 Specification Implementations
7.9.6 Assemble Specification Instances
7.9.7 Internals *
7.9.8 Metamodel Classes
7.9.9 Cons of Using the Criteria API
7.10 Alternatives to JDBC Jakarta Persistence
7.10.1 Querydsl
7.10.2 Spring Data JDBC
7.11 Good Design with Repositories
7.11.1 Abstractions through the Onion Architecture
7.11.2 Think of the Interface Segregation Principle and the Onion!
7.11.3 Fragment Interface
7.12 Projections
7.12.1 Perform Projections Yourself
7.12.2 Projections in Spring Data
7.12.3 Interface-Based Projection
7.12.4 Projections with SpEL Expressions
7.12.5 Projections with Default Methods
7.12.6 Class-Based Projections
7.12.7 Dynamic Projections
7.13 [Fetchable]FluentQuery *
7.14 Auditing *
7.14.1 Auditing with Spring Data
7.14.2 Auditing with Spring Data JPA
7.14.3 AuditorAware for User Information
7.14.4 Outlook: Spring Data Envers
7.15 Incremental Data Migration
7.15.1 Long Live the Data
7.15.2 Evolutionary Database Design
7.15.3 Incremental Data Migration with Flyway
7.15.4 Flyway in Spring Boot: Migration Scripts
7.15.5 Migrations in Java Code
7.15.6 Flyway Migrations outside Spring
7.16 Test the Data Access Layer
7.16.1 What Do We Want to Test?
7.16.2 Test Slices
7.16.3 Deploy an In-Memory Test Database
7.16.4 Assign Connection to the Test Database
7.16.5 Build Tables with Initialization Scripts
7.16.6 Testcontainers Project
7.16.7 Demo Data
7.16.8 @Sql and @SqlGroup
7.16.9 TestEntityManager
7.17 Summary
8 Spring Data for NoSQL Databases
8.1 Not Only SQL
8.2 MongoDB
8.2.1 MongoDB: Documents and Collections
8.2.2 About MongoDB
8.2.3 Install and Start the MongoDB Community Server
8.2.4 GUI Tools for MongoDB
8.2.5 Spring Data MongoDB
8.2.6 MongoDB Application Programming Interfaces
8.2.7 MongoDB Documents
8.2.8 MongoTemplate Class
8.2.9 MongoDB Repositories
8.2.10 Test MongoDB Programs
8.3 Elasticsearch
8.3.1 Text Search Is Different
8.3.2 Apache Lucene
8.3.3 Documents and Fields
8.3.4 Index
8.3.5 Weaknesses of Apache Lucene
8.3.6 Lucene Attachments: Elasticsearch and Apache Solr
8.3.7 Install and Launch Elasticsearch
8.3.8 Spring Data Elasticsearch
8.3.9 Documents
8.3.10 ElasticsearchRepository
8.3.11 @DataElasticsearchTest
8.4 Summary
9 Spring Web
9.1 Web Server
9.1.1 Java Web Server
9.1.2 Spring Boot Starter Web
9.1.3 Use Other Web Servers *
9.1.4 Adjust Port via server.port
9.1.5 Serve Static Resources
9.1.6 WebJars
9.1.7 Transport Layer Security Encryption
9.2 Generate Dynamic Content
9.2.1 Stone Age: The Common Gateway Interface
9.2.2 Servlet Standard
9.2.3 Program @WebServlet
9.2.4 Weaknesses of Servlets
9.3 Spring Web MVC
9.3.1 Spring Containers in Web Applications
9.3.2 @Controller
9.3.3 @RestController
9.3.4 Controller to [Service] to Repository
9.4 Hot Code Swapping
9.4.1 Hot Swapping of the Java Virtual Machine
9.4.2 Spring Developer Tools
9.5 HTTP
9.5.1 HTTP Request and Response
9.5.2 Set Up an HTTP Client for Testing Applications
9.6 Request Matching
9.6.1 @RequestMapping
9.6.2 @*Mapping
9.6.3 More General Path Expressions and Path Matchers
9.6.4 @RequestMapping on Type
9.7 Send Response
9.7.1 HttpMessageConverter in the Application
9.7.2 Format Conversions of Handler Method Returns
9.7.3 Mapping to JSON Documents
9.7.4 ResponseEntity = Statuscode + Header + Body
9.8 Evaluate Request
9.8.1 Handler Methods with Parameters
9.8.2 Data Transmission from Client to Controller
9.8.3 Data Acceptance via Parameters
9.8.4 Evaluate Query Parameters
9.8.5 Optional Query Parameters
9.8.6 Map All Query Parameters
9.8.7 Evaluate a Path Variable
9.8.8 MultipartFile
9.8.9 Evaluate Header
9.8.10 HttpEntity Subclasses RequestEntity and ResponseEntity *
9.9 Type Conversion of the Parameters
9.9.1 YearMonth Converter Example
9.9.2 @DateTimeFormat and @NumberFormat
9.9.3 Map Query Parameters and Form Data to a Bean
9.9.4 Register Your Own Type Converters
9.9.5 URI Template Pattern with Regular Expressions
9.10 Exception Handling and Error Message
9.10.1 Map Exceptions to Status Codes Yourself
9.10.2 Escalates
9.10.3 Configuration Properties server.error.*
9.10.4 Exception Resolver
9.10.5 Map Exception to Status Code with @ResponseStatus
9.10.6 ResponseStatusException
9.10.7 Local Controller Exception Handling with @ExceptionHandler
9.10.8 RFC 7807: “Problem Details for HTTP APIs”
9.10.9 Global Controller Exception Handling with Controller Advice
9.11 RESTful API
9.11.1 Principles behind REST
9.11.2 Implement REST Endpoints for Profiles
9.11.3 Data Transfer Objects
9.11.4 Best Practice: Don’t Deliver a Complete Collection at Once
9.11.5 GET and DELETE on Individual Resources
9.11.6 POST and PUT with @RequestBody
9.11.7 UriComponents
9.12 Asynchronous Web Requests *
9.12.1 Long Queries Block the Worker Thread
9.12.2 Write Asynchronously to the Output
9.12.3 A Handler Method Returns Callable
9.12.4 WebAsyncTask
9.12.5 A Handler Method Returns DeferredResult
9.12.6 StreamingResponseBody
9.13 Spring Data Web Support
9.13.1 Loading from the Repository
9.13.2 Pageable and Sort as Parameter Types
9.13.3 Return Type Page
9.13.4 Querydsl Predicate as a Parameter Type
9.14 Documentation of a RESTful API with OpenAPI
9.14.1 Description of a RESTful API
9.14.2 OpenAPI Specification
9.14.3 Where Does the OpenAPI Document Come From?
9.14.4 OpenAPI with Spring
9.14.5 springdoc-openapi
9.14.6 Better Documentation with OpenAPI Annotations
9.14.7 Generate Java Code from an OpenAPI Document
9.14.8 Spring REST Docs
9.15 Testing the Web Layer
9.15.1 Test QuoteRestController
9.15.2 Annotation @WebMvcTest
9.15.3 Writing a Test Method with MockMvc
9.15.4 Test REST Endpoints with the Server
9.15.5 WebTestClient
9.16 Best Practices When Using a RESTful API
9.16.1 Jakarta Bean Validation
9.16.2 Resource ID
9.16.3 Map Data Transfer Objects
9.16.4 Versioning of RESTful Web Services
9.17 Secure Web Applications with Spring Security
9.17.1 The Importance of Spring Security
9.17.2 Dependency on Spring Boot Starter Security
9.17.3 Authentication
9.17.4 SecurityContext and SecurityContextHolder
9.17.5 AuthenticationManager
9.17.6 SpringBootWebSecurityConfiguration
9.17.7 AuthenticationManager and ProviderManager
9.17.8 UserDetailsService Interface
9.17.9 Spring-Managed Bean PasswordEncoder
9.17.10 BasicAuthenticationFilter
9.17.11 Access to the User
9.17.12 Authorization and the Cookie
9.17.13 Token-Based Authentication with JSON Web Tokens
9.18 Consume RESTful Web Services
9.18.1 Classes for Addressing HTTP Endpoints
9.18.2 A WebClient Example
9.18.3 Declarative Web Service Clients
9.19 Summary
10 Logging and Monitoring
10.1 Logging
10.1.1 Why Create a Protocol?
10.1.2 Log Group
10.2 Logging Implementation
10.2.1 Conversion to Log4j 2
10.2.2 Logging Pattern Layout
10.2.3 Change the Logging Configuration
10.2.4 Banner
10.2.5 Logging at Start Time
10.2.6 Testing Written Log Message
10.3 Monitor Applications with Spring Boot Actuator
10.3.1 Determine the Health Status via the Actuator
10.3.2 Activation of the Endpoints
10.3.3 Info Supplements
10.3.4 Parameters and JSON Returns
10.3.5 New Actuator Endpoints
10.3.6 Am I Healthy?
10.3.7 HealthIndicator
10.3.8 Metrics
10.4 Micrometer and Prometheus
10.4.1 Micrometer
10.4.2 Prometheus: The Software
10.5 Summary
11 Build and Deployment
11.1 Package and Run Spring Boot Programs
11.1.1 Deployment Options
11.1.2 Launching a Spring Boot Program via Maven
11.1.3 Packing a Spring Boot Program into a Java Archive
11.1.4 spring-boot-maven-plugin
11.2 Spring Applications in the OCI Container
11.2.1 Container
11.2.2 Install and Use Docker
11.2.3 H2 Start, Stop, Port Forwarding, and Data Volumes
11.2.4 Prepare a Spring Boot Docker Application
11.2.5 Docker Compose
11.2.6 Terminate Applications with an Actuator Endpoint
11.3 Summary
A Migration from Spring Boot 2 to Spring Boot 3
A.1 Preparation
A.2 Jakarta EE 9
A.3 Other Innovations
A.4 Spring-Boot-Properties-Migrator
A.5 Spring Boot Migrator Project
A.6 Dependency Upgrades
B The Author
Index
Service Pages
Legal Notes