Spring Asynchronous Execution using @Async

In this tutorial we will discuss about the asynchronous execution support in Spring using the @Async annotation. There are cases in which @Async is necessary to execute piece of code asynchronous. An example would be while sending a (JMS) message from one system to another system. The advantage is that the user does not have to wait for the response while the message is being send.
@Async annotation on a method of a bean will execute in a separate thread i.e. the caller does not need to wait for the completion of the called method.

Continue reading “Spring Asynchronous Execution using @Async”

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 the live database but you want to connect to in-memory database such as H2 or Derby or any other in-memory database due to having some constraints connecting from local system and when you deploy your code into other environments such as Dev, SIT, UAT, PROD then during this time only you want to connect to the live database. So in such situtation you may have two persistence units one for local and another for all other environments with the same schema. Therefore you want to pass a VM argument that will take your environment value and will connect to the appropriate persistence unit. Continue reading “Conditional Statement in Spring Config”

Spring MVC Bean Validator

In this example, I will show you how to build a bean validator for User model object.In my previous example, Spring MVC Custom Validator, I have shown how to validate user input.

Validating input received from the user to maintain data integrity is an important part of application logic.

The Bean Validation model is supported by constraints in the form of annotations placed on a field, method, or class of a JavaBeans component, such as a managed bean.

Constraints can be built in or user defined. User-defined constraints are called custom constraints. Several built-in constraints are available in the javax.validation.constraints package. You can read more on bean validation JavaBeans Validation

Continue reading “Spring MVC Bean Validator”

JSF 2, Spring 4, Hibernate 4 and Maven Integration

In this tutorial I will show you how to integrate JSF 2, Spring 4, Hibernate 4 and Maven. In the previous example Spring 3, JSF 2 and Hibernate 3 integration example , I have shown how to integrate JSF 2, Spring 3 and Hibernate 3 but I have not used maven there.

For this tutorial we will create maven based web project in Eclipse.

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 configurations are required in order to run the application

Eclipse Kepler
JDK 1.8
Tomcat 8
Have maven installed and configured
JSF 2, Spring 4, Hibernate 4 dependencies in pom.xml

Now we will see the below steps how to create a maven based project in Eclipse Continue reading “JSF 2, Spring 4, Hibernate 4 and Maven Integration”

Struts 2, Spring 4, Hibernate 4 and Maven Integration

In this tutorial I will show you how to integrate Struts 2, Spring 4, Hibernate 4 and Maven. In the previous example Integrate Spring 3, Struts 2 and Hibernate 3 , I have shown how to integrate Struts 2, Spring 3 and Hibernate 3 but I have not used maven there.

For this tutorial we will create maven based web project in Eclipse.

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 configurations are required in order to run the application

Eclipse Kepler
JDK 1.8
Tomcat 8
Have maven installed and configured
Struts 2, Spring 4, Hibernate 4 dependencies in pom.xml

Now we will see the below steps how to create a maven based project in Eclipse Continue reading “Struts 2, Spring 4, Hibernate 4 and Maven Integration”

Send email with multiple attachments via Spring

This tutorial will show you how to send a basic mail via Spring framework’s email support.

The Spring Framework provides a helpful utility library for sending email that shields the user from the specifics of the underlying mailing system and is responsible for low level resource handling on behalf of the client. A class that comes in pretty handy when dealing with JavaMail messages is the org.springframework.mail.javamail.MimeMessageHelper class, which shields you from having to use the verbose JavaMail API. Using the MimeMessageHelper it is pretty easy to create a MimeMessage. Multipart email messages allow for both attachments and inline resources. Continue reading “Send email with multiple attachments via Spring”

Send email using email template library via Spring

This tutorial will show you how to send a basic mail via Spring framework’s email support.

The Spring Framework provides a helpful utility library for sending email that shields the user from the specifics of the underlying mailing system and is responsible for low level resource handling on behalf of the client. A class that comes in pretty handy when dealing with JavaMail messages is the org.springframework.mail.javamail.MimeMessageHelper class, which shields you from having to use the verbose JavaMail API. Using the MimeMessageHelper it is pretty easy to create a MimeMessage.

The code in the other email sending examples in this site explicitly created the content of the email message, using methods calls such as message.setText(..). This is fine for simple cases, and it is okay in the context of the aforementioned examples, where the intent was to show you the very basics of the API. Continue reading “Send email using email template library via Spring”