Posts

@Sql - Spring Testing Annotation

Image
In this tutorial, we will learn about the @Sql annotation, and at the end, we will see how the Spring Boot application can utilize the @Sql annotation for testing. Therefore, read the post till the end. About @Sql The @Sql is a part of the org.springframework.test.context.jdbc  package. It can be applied at the test class level or the test method level.  Within the Spring testing context, SQL scripts and statements are executed against a database using the Spring @Sql annotation. @Sql declarations at the method level take precedence over those at the class level. But we can change this behavior by configuring @SqlMergeMode .  The annotation supports the following attributes: scripts statements executionPhase config value 1. scripts It specifies the path on which SQL scripts should run. The following example shows how to use it: @Sql (scripts = { "/create-schema.sql" }) public class StudentRepositoryTests { We can specify the path of multiple SQL scripts, like below. @Sql

Spring Core | BeanFactoryPostProcessor | Example

Image
In Spring, the  BeanFactoryPostProcessor is a  functional interface that contains a abstract method postProcessBeanFactory .   It allows us to modify the Spring context’s bean definitions before any beans get created.  BeanFactoryPostProcessor can create new bean definitions or modify existing ones. Since  BeanFactoryPostProcessor  should be called before other bean types are formed, it must be registered as a static method level. BeanFactoryPostProcessor example We are creating a simple maven project. You could clone the code from our GitHub repo. Final Project Directory Complete pom.xml <? xml version ="1.0" encoding ="UTF-8" ?> < project xmlns ="http://maven.apache.org/POM/4.0.0" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi :schemaLocation ="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion >4.0.0</ modelVersion > < gr