Pro Spring Boot 3 with Kotlin: In-Depth Guide to Best Practices for Cloud-Native and Microservices Development. 3 Ed

Pro Spring Boot 3 with Kotlin: In-Depth Guide to Best Practices for Cloud-Native and Microservices Development. 3 Ed

Pro Spring Boot 3 with Kotlin: In-Depth Guide to Best Practices for Cloud-Native and Microservices Development. 3 Ed
Автор: Gutierrez Felipe, Späth Peter
Дата выхода: 2025
Издательство: Apress Media, LLC.
Количество страниц: 922
Размер файла: 6,7 МБ
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы  Дополнительные материалы 

Table of Contents....5

About the Authors....14

About the Technical Reviewer....15

Introduction....16

Part I: Introduction....17

Chapter 1: Spring Boot Quick Start....18

Project: Users App....18

Initial Setup....18

Start @ start.spring.io....19

Testing the Users App Project....29

Running the UserApplicationTests Class....33

Running the Users App Project....34

Why Spring Boot?....40

Spring Boot Features....43

Summary....45

Chapter 2: Spring Boot Internals....46

Requirements to Create a Spring Boot App....46

Project: My Retro App....48

Auto-Configuration....55

@EnableAutoConfiguration, @Enable, and @Conditional* Annotations....59

@EnableAutoConfiguration....59

@Enable....60

@Conditional*....61

Spring Boot Features....63

Custom Banner....65

SpringApplicationBuilder....72

Application Arguments....75

Executable JAR....77

ApplicationRunner, CommandLineRunner, and ApplicationReadyEvent....77

Application Configuration....80

My Retro App and Users App Project Integration....80

Configuration Properties....83

Relaxed Binding....85

Configuration Precedence....86

Changing Defaults....87

Application Profiles....88

Summary....89

Chapter 3: Spring Boot Web Development....90

Spring MVC....90

Spring Boot MVC Auto-Configuration....91

My Retro App Project....93

Adding Dependencies....96

AOP to the Rescue....107

Spring Web Annotated Controllers....110

Testing My Retro App....117

Users App Project....123

Spring Web Functional Endpoints....129

Testing the Users App....134

Spring Boot Web: Overriding Defaults....138

Overriding Default Server Settings....139

JSON Date Format....140

Using a Different Application Container....141

Spring Boot Web Clients....141

Testing the Client....145

Summary....146

Chapter 4: Spring Boot SQL Data Access....147

Spring Boot Features for SQL Databases....147

Spring Framework Data Access....148

JDBC with Spring Boot....149

Users App: Using Spring Boot JDBC....150

Gravatar: Identifying the User....153

Model: enum and record Types....153

JdbcTemplate and RowMapper....155

Adding the Web Controller....158

Adding Users when the App Is Ready....161

Database Initialization....163

Testing the Users App....164

But Wait... What Happened with the Tests?....167

Running the Users App....168

Using PostgreSQL....171

My Retro App: Using Spring Boot JDBC....174

Running the My Retro App....193

But Wait... What... Again?....195

Summary....195

Chapter 5: Spring Data with Spring Boot....197

Spring Data....197

Spring Data JDBC....198

Spring Data JDBC with Spring Boot....199

Users App with Spring Boot and Spring Data JDBC....199

Testing the Users App....211

Running the Users App....214

My Retro App with Spring Boot and Spring Data JDBC....215

Running the My Retro App....222

Spring Data JPA....225

Spring Data JPA with Spring Boot....226

Users App with Spring Boot and Spring Data JPA....226

Testing and Running the Users App....232

My Retro App Using Spring Boot and Spring Data JPA....233

Running the My Retro App....242

Spring Data REST....243

Spring Data REST with Spring Boot....244

Users App Using Spring Boot and Spring Data REST....244

Running the Users App....248

Testing the Users App....256

My Retro App Using Spring Boot and Spring Data REST....260

Run the My Retro App....263

Summary....267

Chapter 6: Spring Data NoSQL with Spring Boot....269

Spring Data MongoDB....269

Spring Data MongoDB with Spring Boot....270

Users App with Spring Data MongoDB and Spring Boot....270

Testing the Users App....278

Running the Users App....281

My Retro App with Spring Data MongoDB Using Spring Boot....283

Running My Retro App....294

Spring Data Redis....299

Spring Data Redis with Spring Boot....300

Users App with Spring Data Redis Using Spring Boot....300

Testing the Users App....307

Running the Users App....310

My Retro App with Spring Data Redis Using Spring Boot....312

Running My Retro App....316

Summary....319

Chapter 7: Spring Boot Reactive....320

Reactive Systems....320

The Reactive Manifesto....320

Project Reactor....322

Mono, an Asynchronous [0|1] Result....322

Flux: An Asynchronous Sequence of [0|N] Items....323

Reactive Web and Data Applications with Spring Boot....323

Users App with Spring Boot Reactive....325

Testing the Users App....335

Running the Users App....338

My Retro App with Spring Boot Reactive....339

Running My Retro App....353

Summary....354

Chapter 8: Spring Boot Testing....355

Spring Testing Framework....355

Spring Boot Testing Framework....357

Testing Web Apps with a Mock Environment....358

Using Mocking and Spying Beans....362

Testcontainers....366

Spring Boot Testing Slices....368

@JsonTest....370

@WebMvcTest....374

@DataJpaTest....379

@WebFluxTest....382

@DataMongoTest....386

Using Testcontainers to Run Your Spring Boot Applications....389

Summary....391

Part II: Spring Cloud Data Flow: Internals....392

Chapter 9: Spring Boot Security....393

Spring Security....393

Spring Security with Spring Boot....396

Adding Security to Users App....397

Users App Web Controller....403

Testing Security in Users App....403

Mocking Security Tests....406

Using Persistence for Security Authentication in Users App....408

Using Custom Persistence for Your Authentication Security....411

Connecting a UI to Users App....415

Users Frontend/Backend: Let’s Give It a Try!....418

Adding Security to My Retro App....422

Unit Testing My Retro App Security for Authorization....435

Putting Everything Together: UI, Users App, and Retro App....440

Adding a Social Login with OAuth2....443

Social Login to Users App....444

Running Users App with Social Login....452

The Spring Authorization Server....455

Getting Started....456

Using the Spring Authentication Server with Users App....461

Running Users App....467

Wait... What About My Retro App?....470

Summary....471

Chapter 10: Messaging with Spring Boot....472

Messaging As a Concept....472

Messaging with Spring Boot....473

Events with Spring Boot....475

Adding Events to Users App....476

JMS with Spring Boot....479

Which Broker Are We Using?....481

Users App with JMS....481

Running Users App....487

Listen for Incoming User Events with JMS....492

Rerunning Users App....494

Using JMS Topics with My Retro App....495

Running My Retro App....502

AMQP with Spring Boot....503

Installing RabbitMQ....503

RabbitMQ/AMQP: Exchanges, Bindings, and Queues....504

Using AMQP with RabbitMQ in Users App....506

Publishing Messages to RabbitMQ....509

Running Users App with RabbitMQ....514

Consuming Messages from RabbitMQ....521

Running Users App with RabbitMQ to Consume Messages....525

Using RabbitMQ in My Retro App to Consume User Events....525

Running My Retro App to Listen for User Events from RabbitMQ....529

WebSockets with Spring Boot....531

Adding WebSockets to Users App....532

Using the WebSockets Client in Users App to Consume Events....536

Running Users App with WebSockets....539

Using WebSockets in My Retro App to Consume Events....540

Running My Retro App Using WebSockets/STOMP....549

RSocket with Spring Boot....550

Using RSocket with Users App with Spring Boot....551

Running Users App with RSocket and Spring Boot....555

Requesting RSocket Messages in My Retro App....555

Running the RSocket Requester in My Retro App with Spring Boot....561

Other Messaging Frameworks....562

Summary....562

Chapter 11: Spring Boot Actuator....563

What Is Spring Boot Actuator?....563

Users App with Spring Boot Actuator....564

/actuator....567

Configuring /Actuator Endpoints....569

Using Spring Profiles for Actuator Endpoints....570

Enabling Actuator Endpoints....571

/actuator/info....571

/actuator/env....576

/actuator/beans....578

/actuator/conditions....579

/actuator/configprops....580

/actuator/heapdump....581

/actuator/threaddump....581

/actuator/mappings....583

/actuator/loggers....585

/actuator/metrics....586

/actuator/shutdown....590

Adding Security....590

/actuator/auditevents....594

Implementing Custom Actuator Endpoints....596

Accessing Custom Endpoints with JMX....601

More Spring Boot Actuator Configuration....607

CORS Support....607

Changing the Server Address, Port, and Base Path....607

Using SSL with Spring Boot Actuator....608

Configuring Endpoints....608

Overview of /actuator/health....609

Health Indicators....611

A Custom Health Indicator for Users App....614

My Retro App with Spring Boot Actuator Observability: Metrics, Logs, and Tracing....618

Adding Observability to My Retro App....618

Adding Custom Metrics and Observations....621

Adding an External Request with the New @HttpExchange....624

Adding Logging Using Grafana Loki....632

Declaring Services in Docker Compose....635

Ready to Run!....639

Observing with Grafana and Prometheus—Metrics, Logs, and Tracing....641

What About External Resources: Memory, CPU, and Storage?....649

Summary....656

Chapter 12: Spring Boot Native and AOT....657

What Is Spring AOT?....657

What Is GraalVM?....659

Benefits of Using GraalVM....659

Examples of Using GraalVM....660

Spring, Spring Boot, and GraalVM....662

AOT Processing in Spring....663

Creating GraalVM Native Apps....665

Creating a Native Users App....665

Creating a Native My Retro App....676

GraalVM Native Images, wait... What?....685

Creating Native Image for Users App....686

Inspecting the User’s Native Image....687

Creating a My Retro App Native Image....688

Inspecting the My Retro Native Image....689

Testing Native Apps and Images....690

AOT Processing with Custom Hints....690

Summary....692

Chapter 13: Spring Cloud with Spring Boot....693

Challenges Addressed by Spring Cloud....693

Microservices....695

Twelve-Factor App Practices and Spring Boot/Spring Cloud Relationship....696

Cloud Development....699

Using Spring Cloud Technologies....701

HashiCorp Consul and Spring Cloud Consul....703

HashiCorp Consul....704

Using HashiCorp Consul....705

Spring Cloud Consul....708

Using Spring Cloud Consul in Users App....710

Running Users App with Spring Consul....716

Reviewing the UserProperties....719

Using a YAML Format Instead of a Key/Value Pair as a Configuration....721

Using Spring Cloud Consul in My Retro App....724

Using OpenFeign in My Retro App....727

Running My Retro App....735

HashiCorp Vault and Spring Cloud Vault....736

HashiCorp Vault....736

Using HashiCorp Vault with Credentials Creation for PostgreSQL....738

Spring Cloud Vault....744

Implementing Credential Generation on the Users Service App Using HashiCorp Vault....746

Running Users App with Vault....748

Fixing Credential Rotation by Adding a Listener....749

Using Spring Cloud Gateway....753

Creating a My Retro Gateway....754

Running the My Retro Gateway....758

More Gateway Features....762

CircuitBreaker Filter....762

Adding the CircuitBreaker Filter to the My Retro Gateway App....763

Integrating the Cloud Environment into Docker Compose....766

Creating Multi-Architecture Images....771

Using a Cloud Platform: Kubernetes....773

Using Kubernetes....775

Prerequisites: Installation....775

Starting Minikube....775

Creating the Postgres Deployment....776

ConfigMap....776

PersistentVolume and PersistentVolumeClaim....776

Deployment....777

Service....779

Installing the Declarations....779

Deploying Microservices in Kubernetes: Users App, My Retro App, and My Retro Gateway App Deployments....780

ClusterRole and ClusterRoleBinding....780

Users Deployment and Service....781

My Retro Deployment and Service....784

My Retro Gateway ConfigMap, Deployment, and Service....786

Access to My Retro Gateway: Using Port-Forward....790

Cleaning Up....790

Summary....791

Chapter 14: Extending Spring Boot....792

Benefits of a Custom Starter....792

Revisiting @Conditional and @Enable....793

Requirements of the Custom Spring Boot Starter....795

Rules and Guidelines for a Custom Spring Boot Starter....797

Creating My Retro Spring Boot Starter....798

Building the myretro-spring-boot-starter Custom Starter....819

Publishing the Custom Starter in GitHub as a Maven Artifact....820

Using the myretro-spring-boot-starter Custom Starter....825

Running Users App with myretro-spring-boot-starter....833

Summary....835

Chapter 15: Spring Boot New Projects....837

Spring Modulith....837

Comparing Spring Modulith with Microservices....837

Choosing the Right Approach....838

Fundamentals....839

Understanding Module Packages in Spring Boot....841

Using Spring Modulith in the My Retro Solution....842

Running the My Retro Solution....854

Spring AI....855

AI Concepts....855

Models....855

Prompts....856

Prompt Templates....857

Embeddings....857

Tokens....858

Teaching AI New Tricks: Beyond the Training Dataset....859

Creating a Chat GPT Client....859

Running the App....862

Summary....862

Appendix A: Spring Boot Migration....863

Migrating Spring Security....863

Using HttpSecurity....863

WebSecurity Configuration....864

LDAP Authentication....865

In-Memory Authentication....866

JDBC Authentication....867

Upgrading to Spring Boot 3....869

Using Configuration Properties Migration....872

Spring Boot Migrator....873

Summary....873

Appendix B: Spring Boot GraphQL....874

What Is GraphQL?....874

Spring for GraphQL....876

Spring for GraphQL and Spring Boot: A Match Made in Developer Heaven....877

Using GraphQL in Users App....878

The Users GraphQL Controller....883

The Users GraphQL Schema....886

Running Users App....890

Using GraphQL in My Retro App....895

Summary....901

Index....902

Quickly and productively build complex Kotlin-based Spring applications and microservices out of the box, with minimal concern over things such as configurations. This revised edition will show you how to fully leverage the Spring Boot 3 micro-framework and apply it to create enterprise-ready Kotlin-based cloud-native applications, microservices, and web applications that just work.

The book covers what has been added to the new Spring Boot 3 release, including improved support for the Kotlin programming language, changes to Stream Editor UI, Maven Preemptive Authentication, building Docker images using cloud-native build packs, building layered jars for optimized Docker images, E2E traceability for configuration properties, many dependency upgrades, support for Spring Data, and much more.

This book is your in-depth pragmatic guide for increasing your enterprise Kotlin and cloud application productivity while decreasing development time. It is a no-nonsense guide with case studies of increasing complexity throughout the book. The main author, a senior solutions architect and Principal Technical instructor at Pivotal, the company behind the Spring Framework, shares his experience, insights, and first-hand knowledge about how Spring Boot technology works, and best practices.

This is an essential book for your Kotlin-based Spring learning and reference library.

What You Will Learn

  • Build cloud-native apps and microservices with the Spring Boot 3 framework
  • Persist and access your data using and integrating with Spring Data
  • Message with Kafka, RabbitMQ, and WebSockets
  • Explore Spring Cloud projects
  • Extend Spring Boot by creating your own Spring Boot Starter and @Enable feature
  • Test and deploy Spring Boot with best practices
  • Effectively use Kotlin as a programming language for Spring applications

Who This Book Is For

Experienced Spring, Java, and Kotlin developers seeking increased productivity gains and decreased complexity and development time in their applications and software services


Похожее:

Список отзывов:

Нет отзывов к книге.