Return to site

๐Ÿƒ๐ŸŽ“ SPRING CERTIFICATION QUESTION: How do you configure a DataSource in Spring? Which bean is beneficial for development/test databases?

October 29, 2022

Answer:

DataSource is a factory to obtain database connections. There're several ways to create DataSource beans in a Spring application:

- using JNDI lookup

- using JDBC DataSource vendors

- using test-purpose DataSource implementations provided by Spring Framework (e.g. DriverManagerDataSource, SingleConnectionDataSource, embedded Datasource created via EmbeddedDatabaseBuilder class).

Preferable development DataSource is a pooled-Datasource obtained by JNDI lookup. For testing purposes, embedded Datasource EmbeddedDatabase is sometimes sufficient.

Examples of mentioned terms:

SampleDataSourceConfiguration - basic example for configuring production/development Datasource s.(in the attachment below)๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡

#spring #certificationquestion #vcp