Spring @PostConstruct and @PreDestroy Example

In this tutorial I will show you how we can use @PostConstruct and @PreDestroy annotation in Spring framework. @PostConstruct and @PreDestroy annotations are generally considered best practices for receiving life cycle callbacks in a modern Spring application. Using these annotations means that our beans are not coupled to Spring specific interfaces. Sometimes we need to load some data or perform…

Select Single and Multiple Records using Spring JdbcTemplate

Record Selection Using Spring JdbcTemplate This tutorial will show you how you can select or fetch data from a database using Spring JdbcTemplate. I am going to use Spring Boot framework to select single record, multiple records and only single field or column value from the database. simplifies the use of JDBC and helps to avoid common errors. It executes…

Single and Multiple Records Insert using Spring JdbcTemplate

Records Insertion Using Spring Jdbc Template This tutorial will show you how you can insert an object or multiple objects into a database using Spring JdbcTemplate. So you are going to see how to insert single record and multiple records into database table. I am going to use PreparedStatement and BatchPreparedStatementSetter for inserting multiple records. Sometimes you need to insert…

How to concurrently execute tasks using Java in Spring

This tutorials will show you how we can concurrently execute different operations using Java utility class called java.util.concurrent.Executors in Spring framework. Spring supports XML as well as Programmatic configuration of beans but, here we will use XML based metadata configuration. If you already have an idea on how to create a maven project in Eclipse will be great otherwise I…

Embedded HSQL Database with Spring

Introduction This tutorial will show you how you can work with embedded HSQLDB with Spring framework. This application will show you a CRUD (Create, Read, Update and Delete) operation using embedded HSQLDB. Sometimes you need to work with an in memory database when you want to demonstrate certain database centric features of an application during development phase. Such situation may…

Compound Property Names in Spring

With this example I will show you how compound or nested property names work in Spring application. Compound or nested property names are perfectly legal when setting bean properties, as long as all components of the path except the final property name are non-null. You can use compound or nested property names when you set bean properties, as long as…

Depends-on in Spring

With this example I will show you how depends-on (@DependsOn annoattion) works in Spring application. Depends-on is basically used when you have a dependency on another bean without which you cannot proceed with the execution of your operations in current bean. Or if you need to initialize any bean before another bean, depends-on does this job. While creating bean you…

Collection merging in Spring

With this example we will show you how to merge Collections in Spring. Since Spring 2.0, the container supports merging of collections. You can define <prop/>, <list/>, <map/> and <set/> of parent-style and then you can inherit the child-style element and override values of each type from parent collections. That is, the child collection’s values are the result of merging…

Collection Element Set In Spring

Introduction Here in this example I am going to show you how to work with collection element set in Spring Boot application. Actually, a set of properties will be injected into a Spring bean. These properties are configurable in theĀ application.propertiesĀ or XML configuration files. So, you declare set of values in the configuration or properties file and Spring bean pick them…

Working with Collection Element Type Map in Spring Application

With this example I will show you how to inject Collection Type Map in Spring Bean. I am going to show you in Spring Boot framework how to read map based key/value pair. I will also show you how to read the map based values from traditional XML config file. In order to show how Collections can be injected in…