chapter twelve

12 Using data sources in Spring apps

 

This chapter covers

  • What a data source is
  • Configuring a data source in a Spring app
  • Using JdbcTemplate to work with a database

Almost every app today needs to store data it works with, and often apps use databases to manage the data they persist. For many years, relational databases have provided applications with a simple and elegant way to store data that can be successfully applied in many scenarios. Spring apps, like other apps, often need to use databases to persist data, and for this reason, you need to learn how to implement such capabilities for your Spring apps.

Figure 12.1 shows your progress up to this point on learning to use Spring to implement various fundamental capabilities in a system. We have made good progress, and you can now use Spring to implement capabilities in various parts of a system.

Figure 12.1 You already understand the essential parts you implement with Spring in a system. At the beginning, you learned the fundamentals and what makes Spring able to provide the capabilities you use in your apps. Then you learned to implement web apps and REST endpoints to establish communication between the system’s components. You now start your journey in learning the valuable skills of making your Spring app work with persisted data.

We continue our discussion with what a data source is and the most straightforward way to make your Spring app work with a database: the JdbcTemplate tool that Spring offers.

12.1 What a data source is

12.2 Using JdbcTemplate to work with persisted data

12.3 Customizing the configuration of the data source

12.3.1 Defining the data source in the application properties file

12.3.2 Using a custom DataSource bean

12.4 Questions

12.5 Summary