Conditional Statement in Spring Config

Sometimes we may need to have some conditional statement in Spring config XML file depending upon some variables value. Think of a situation when you are using JPA in your application and your application may have two persistence units in Spring XML config file and you need to connect to one of them depending upon the environments. Here conditional statement…

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…

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…

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…

Batch Insert using Spring JdbcTemplate

This tutorial will show you how you can insert a large dataset or perform batch insert into a database at once using Spring JdbcTemplate. Sometimes you need to insert or update large number of records in the database. It’s not a good idea to insert multiple records into database one by one in a traditional approach. It will hit the…

Spring 3, REST using Jersey 2.6 and Grizzly integration example

In this tutorial I will show you how to integrate REST using Jersey 2.6, Spring 3 and Grizzly web server. So I will use here Grizzly web server so we don’t need to use any other external webserver. I had been googling for many times but I did not get any satisfactory example on REST using Jersey 2.6 with Spring…

Spring AOP (Aspect Oriented Programming) Example

With this tutorial we will see how to use Aspect Oriented Programming in Spring Framework. AOP is used in the Spring Framework to provide declarative enterprise services. It is also used to allow users to implement custom aspects, complementing their use of OOP with AOP. We will demonstrate how to create and apply some central AOP concepts. In short we…

Integrate Spring 3, Struts 2 and Hibernate 3

Introduction This tutorial shows how to integrate Spring 3, Struts 2 and Hibernate 3 in the following example. In this example, Struts 2 will be used as a web framework and Spring 3 will be used as a core service. We will use ORM (Object Relational Mapping) framework Hibernate for our persistent layer to interact with database. We are going…