liveBook · Manning

Chapter 12: Using data sources in Spring apps

What you will learn in chapter 12 of Spring Start Here, Second Edition

The introduction explains why database persistence matters to Spring apps and introduces the chapter’s topic without teaching its implementation.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why database persistence matters to Spring apps and introduces the chapter’s topic without teaching its implementation.

Key terms: persist data, relational databases, Spring apps

12.1 What a data source is

This section explains why Spring apps use a data source to manage database connections and how JDBC drivers enable connections to specific DBMS technologies.

Key terms: data source, connection, DBMS, persistence layer, JDBC, JDK, JDBC driver, runtime dependency, HikariCP, Hikari connection pool

12.2 Using JdbcTemplate to work with persisted data

This section builds a small Spring app that uses JdbcTemplate to store and retrieve purchases through REST endpoints.

Key terms: JdbcTemplate, update(), JDBC, INSERT, UPDATE, DELETE, purchase, schema.sql, DDL, BigDecimal

12.3 Customizing the configuration of the data source

This section explains why a production app may need a configured data source rather than the in-memory H2 database used to get started.

Key terms: H2 database, in-memory database, data source, production apps

12.3.1 Defining the data source in the application properties file

This subsection shows how to switch a Spring app from H2 to an external MySQL database by changing dependencies and application properties, then verify that purchases are persisted.

Key terms: H2, JDBC driver, application.properties, spring.datasource.url, spring.datasource.username, spring.datasource.password, spring.sql.init.mode, always, schema.sql, purchase table

12.3.2 Using a custom DataSource bean

Explains when to define a custom DataSource bean, how to configure it, and how to check that the app still persists purchases.

Key terms: DataSource, Spring Boot, qualifiers, @Bean, @Value, application.properties, Spring context, HTTP POST, HTTP GET, /purchase

12.4 Questions

This section lists questions for reviewing the chapter’s concepts; answers are provided in Appendix A.

12.5 Summary

Summarizes how JDBC drivers, data sources, and JdbcTemplate support relational database access in Spring Boot, including when to customize them.

Where this is used later

Concepts explained in this chapter

← Chapter 11: Consuming REST endpoints Chapter 13: Using transactions in Spring apps →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.