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 in Spring config comes to rescue. For example, when you write code in your local system and want to test the application then you do not want to connect to…

Continue

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 initialization work after all necessary properties on the bean have been set by the container. In this example we will load data from database during application startup and set that…

Continue

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 will tell you here how to create a maven project in Eclipse. Prerequisites The following things are required in order to run the application Eclipse Kepler JDK 1.8 Have maven…

Continue

Depends-on in Spring

With this example we will show you how depends-on works in Spring. In spring application XML, if we need to initialize any bean before another bean, depends-on does this job. While creating bean we need to define depends-on attribute in bean. When a bean is typically dependent on another bean then we specify the dependent bean using <ref/> element in XML-based configuration metadata. However, sometimes dependencies between beans are less direct; for example, a static initializer that initializes something like loading of database driver in a class needs to be…

Continue

Call Stored Procedure using Spring StoredProcedure

This tutorial will show you how we can call stored procedure using Spring StoredProcedure. I assume you have a basic idea on stored procedure what it does and what are the advantages of using stored procedure. I am going to build the project using both maven and gradle build tools. Related Posts: Call Stored Procedure using Spring SimpleJdbcCall Sometimes we need to call a stored procedure while a single SQL statement is unable to fulfil our requirements because, it permits to execute multiple SQL statements and it also allows us…

Continue

Call Stored Procedure using Spring SimpleJdbcCall

This tutorial will show you how we can call or execute stored procedure using Spring SimpleJdbcCall. SimpleJdbcCall API provides flexible methods to invoke stored procedure. We can use DataSource directly with SimpleJdbcCall or we can create JdbcTemplate using DataSource and use JdbcTemplate with SimpleJdbcCall API for calling the stored procedures. We can also use RowMapper or BeanProprtyMapper of type POJO class as a return type while executing stored procedures using Spring’s SimpleJdbcCall API. We are also going to use @Qualifier annotation for resolving ambiguity while using SimpleJdbcCall with DataSource and…

Continue

Batch Insert using Spring JdbcTemplate

This tutorial will show you how we can insert a large dataset or perform batch insert into a database at once using Spring JdbcTemplate. Sometimes we 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 application’s performance. Spring provides batch operations with the help of JdbcTemplate, it inserts or updates records in chunks into database in one shot.

Continue

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 and Grizzly web server. You will get many search results if you search for a REST example using Jersey but you will get most of them are using 1.8. You…

Continue

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 will create all types of advices, we will use a pointcut and an advisor over an advice and we will check on some special features of Spring in interceptors and…

Continue

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 to use MySQL database for our example, you may use any database of your choice. You may also like to read: Struts 2, Spring 4, Hibernate 4 and Maven Integration

Continue