Spring Boot Data JPA Entity DTO Mapping Using MapStruct

Introduction In this example I will show you how to convert entity class to DTO (Data Transfer Object) class and DTO class to entity class using MapStruct. So, MapStruct will map entity class to DTO class or vice versa. This example will test both from RESTful webservices and standalone main class. Spring Boot provides CommandLineRunner interface to run the project…

Spring bean life cycle call back Methods Example

Spring framework provides bean life cycle call back methods to perform some additional tasks which you may want to perform when a bean is initiated or created or when a bean is about to get destroyed. Therefore you can run a method which will do some initialization process during bean initialization and you can run another method which will do…

InitializingBean and DisposableBean in Spring

Spring InitializingBean and DisposableBean are the interfaces used in life cycle of Spring beans management. Each of these interfaces has only one method. InitializingBean has a method called afterPropertiesSet() and DisposableBean has a method called destroy(). Spring container runs the method afterPropertiesSet() once the bean properties have been set and Spring container runs destroy() method once Spring container releases the…

Custom init() and destroy() methods in Spring

Introduction In this tutorial we will discuss on Spring custom init() and destroy() methods. These methods are call back methods which used in Spring life cycle. You can use these methods to to some initialization and clean up jobs just after the bean is created by the Spring container or just before the bean is about to be destroyed by…

How to map Custom Query Results into DTO in Spring Data JPA

Introduction In this tutorial I will show you how to map custom query results into DTO in Spring Data JPA. Situations may occur while you are unable to return the entity object(s) as results from your Spring Data JPA Repository and instead you need to write custom query or native query for your business requirements. So in such situations you…

How to Create Annotation based Spring Application

Introduction We will see how to create annotation based Spring application or annotation based configuration in Spring application. We will use here H2 database to perform database activities using Spring JDBC Template. We will not use any XML configuration here or zero XML configuration. We will also see how to run this stand-alone Spring application using main method. This application…

Spring MVC and JDBC CRUD with zero XML

In my other tutorials Spring MVC CRUD example with JDBC Spring MVC and Spring JDBC Example ,  Spring MVC and JDBC CRUD Example  I have used XML configurations but in this tutorial I have used only Annotation, so it means it uses zero XML configurations. This example shows how MVC(Model, View, Controller) works in Spring 4.x. In this tutorial you will also…

Spring MVC and JDBC CRUD Example

Introduction This tutorial Spring MVC and JDBC CRUD example shows how MVC(Model, View, Controller) works in Spring 4.x. In this tutorial you will also find how JDBC works with Spring MVC. We will also see how annotation like @Autowired works in Spring MVC and JDBC CRUD example. You will also see how datasource is configured in Spring. In this example…

Spring MVC and Spring JDBC Example

Introduction This tutorial shows an example on how MVC (Model, View, Controller) works in Spring framework. In this tutorial you will also find how JDBC (Java Database Connectivity API) works with Spring MVC. We will also see how annotation like @Autowired works in Spring. You will also see how datasource is configured in Spring. This example shows how to read…