Spring Boot - Testing JDBC components with @JdbcTest - Example
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5VTasuWkD8AuD_y4w3aEXqgXRLSJf0VZWqY70hNCyeTZkjw1vmFOG5E3f_grY57FjRYKmPpn78d-uuBCzBxsZ0_kWC8cLbBxKcVUBeCmQ6N4kW7qhQYe5HHaGkegqgimqQIjd35hnWSDC-kF_PMajD8tTautaRJ4RbQvW79TF1MHZv8sHhaR_Nd7iScAA/w640-h366/jdbctest-springboot-dao.png)
In this section, we will learn how to test JDBC-based components with @JdbcTest in Spring Boot application. 1. @ JdbcTest Instead of bootstrapping the entire application context for every test, @JdbcTest allows us to initialize the Spring application context with only those beans needed to test JDBC-based components. It will auto-configure DataSource , and JdbcTemplate . If an embedded database is available on the classpath, @JdbcTest will autoconfigure one for testing purposes. By default, tests annotated with @JdbcTest are transactional and roll back at the end of each test, means we do not need to clean up saved or modified table data after each test. Regular @Component , @Repository , @Service or @Controller beans are not scanned when using this annotation. This approach not only speeds up the testing process but also ensures a focused and efficient testing environment. This approach is also known as " slicing " the application context. Find the sample code snipp