DataSource

Spring Boot

Spring Boot – Separate DataSource for Test, Dev and Prod

Learn to configure and use different DataSource in different environments (test, development, production etc.) using the Spring profile specific properties files, as well as Java configuration in a Spring boot application. 1. Introduction A production grade application is deployed and tested in different environments before finally released to the end-user. In these environments, application must …

Mock JNDI DataSource in JUnit Tests with Hibernate and H2

Test code that looks up a JNDI DataSource without an application server: register a small in-memory JNDI provider or Simple-JNDI, bind an H2 DataSource under the production name, bootstrap Hibernate 7 with it and run CRUD in JUnit 6. Or skip JNDI and pass the DataSource object.

Spring Boot DataSource Configuration with HikariCP Examples

Configure a DataSource in Spring Boot 4 with spring.datasource.url, username and password, and Spring Boot creates a HikariCP pool. Tested examples for pool tuning, DataSourceBuilder, a second DataSource, schema.sql and data.sql, and tests with H2 and Testcontainers.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.