Spring Batch

When we need to perform batch jobs, better to use Spring Batch.
This is matured framework with many options.

1. Easy to configure
2. Repeat options / Retry options
3. Scalability with parallel process
4. Support for multiline records
Many more



Spring Web Services 2 Cookbook

Spring Web Services 2 Cookbook
Paperback: 322 pages
Publisher: Packt Publishing (May 13, 2012)
Language: English
ISBN-10: 1849515824
ISBN-13: 978-1849515825
Books is available at Amazon.com

Spring Web Services 2 Cookbook

This is very nice book on Spring Web Services.

#cookbook, #spring-web, #web-services

New Webapp – Spring, GWT EXT, Restlet, Hibernate,….etc

Problem Statement: How to build very nice rich website?

Option 1: Single tier architecture
Advantages: Saves Time, Easy to implement
Disadvantages: Difficult to break up later to support other user interfaces.

Option 2: Two tier architecture
Advantages: Both are in its own spheres. Easy to modify and re-write later if required.
Disadvantages: Takes more time to setup the environment and looks like more code.

Services: Spring, RESTful Services, Hibernate

RESTful – http://www.xfront.com/REST-Web-Services.html
Restlet with Spring – http://jgoday.wordpress.com/2009/04/10/restlet-with-spring/
RESTful from Wiki: http://en.wikipedia.org/wiki/Representational_State_Transfer
Archetype – HibernateSpringGwt https://opensource.fastconnect.org/redmine/projects/show/spring-gwt-archetype
maven-gwtext-archetype http://code.google.com/p/maven-gwtext-archetype/


#gwt-ext, #hibernate, #restlet, #spring

Spring Bean – Order of injecting properties

Problem Statement: We need to start some task, after injecting all properties. How to resolve this?

Solution: Dont / Never depend on order of injecting values into bean. It is not controlled.

import org.springframework.beans.factory.InitializingBean;

public class BeanName implements InitializingBean

public void afterPropertiesSet() throws Exception
    System.out.println( "It will be called after completion of properties setting.");
    //do whatever is required here.


#afterpropertiesset, #injecting-properties-order, #spring-framework

Injecting boolean values into Spring bean

Problem Statement: How to inject boolean values into spring bean?


<property name="isFlagEnabled" value="true"/>
private boolean isFlagEnabled = false;


<property name="isFlagEnabled">
	<value type="java.lang.Boolean">true</value>
private Boolean isFlagEnabled = false;


#inject-boolean-value, #spring-bean

Spring – Inject Properties file into Bean

Problem Statement: Spring – Inject Properties file into Bean

Spring Bean configuration file

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">

<util:properties id="propertiesFileID1" location="classpath:complete_file_pathfilename.properties"/>

<bean name="BeadID" class = "com.abc.ClassNameABCD" >
	<property name="propFile1" ref="propertiesFileID1"/>


Source code

package com.abc;

import java.util.Properties;

public class ClassNameABCD

 private Properties propFile1;

 //Prepare getter and setters for propFile1;


Read this for more information


Spring – Oracle Connection Pool Configuration

Problem Statement: Configure Oracle Connection Pool in Spring

This is basic data source (Only testing)

&lt;bean id=&quot;datasource1&quot;
&lt;property name=&quot;driverClassName&quot;&gt;
&lt;property name=&quot;url&quot;&gt;
         &lt;value&gt;ORACLE URL&lt;/value&gt;
&lt;property name=&quot;username&quot;&gt;
         &lt;value&gt;user id&lt;/value&gt;
&lt;property name=&quot;password&quot;&gt;
         &lt;value&gt;user password&lt;/value&gt;

This is dbcp data source (Preferred for Testing.)

&lt;bean id=&quot;datasource2&quot;
 class=&quot;org.apache.commons.dbcp.BasicDataSource&quot; destroy-method=&quot;close&quot;&gt;
&lt;property name=&quot;driverClassName&quot;&gt;
&lt;property name=&quot;url&quot;&gt;
         &lt;value&gt;ORACLE URL&lt;/value&gt;
&lt;property name=&quot;username&quot;&gt;
         &lt;value&gt;user id&lt;/value&gt;
&lt;property name=&quot;password&quot;&gt;
         &lt;value&gt;user password&lt;/value&gt;
&lt;property name=&quot;initialSize&quot; value=&quot;5&quot;/&gt;
&lt;property name=&quot;maxActive&quot; value=&quot;20&quot;/&gt;

This is Oracle Connection Pool (Production Quality)

&lt;bean id=&quot;connectionPool1&quot; class=&quot;oracle.jdbc.pool.OracleDataSource&quot; destroy-method=&quot;close&quot;&gt;
&lt;property name=&quot;connectionCachingEnabled&quot; value=&quot;true&quot; /&gt;
&lt;property name=&quot;URL&quot;&gt;
         &lt;value&gt;ORACLE URL&lt;/value&gt;
&lt;property name=&quot;user&quot;&gt;
         &lt;value&gt;user id&lt;/value&gt;
&lt;property name=&quot;password&quot;&gt;
         &lt;value&gt;user password&lt;/value&gt;
&lt;property name=&quot;connectionCacheProperties&quot;&gt;

Oracle Connection Pool is better than DBCP and C3P0


select * from v$version;

“Oracle Database 11g Enterprise Edition Release – 64bit Production”
“PL/SQL Release – Production”
“CORE Production”
“TNS for Linux: Version – Production”
“NLSRTL Version – Production”

Go to Oracle and Choose correct Driver and Download it.

Option 1: Added to Maven Repo and pom.xml

Add jar to maven Repo

Refer it in pom file.

&lt;project ...&gt;
		&lt;!-- ORACLE database driver --&gt;

Option 2: Add the jar file to Lib folder.


Description: Could not locate TransactionManager


Chained Exception Object: org.hibernate.HibernateException
Description: Could not locate TransactionManager

When we use org.springframework.orm.hibernate3.LocalSessionFactoryBean, the following two properties are not required.


org.hibernate.transaction.JTATransactionFactory  --&gt;



Spring Dynamic Modules – OSGi

Last few days I am reading on OSGi. It is difficult to imagine life with out Spring Dynamic Modules for projects who needs to support multiple environments. Example: A jar file needs to work in application server. Also need to work in OSGi container. Spring DM Configuration files will help to achieve this. To know more about it read the following.

1. “Pro Spring Dynamic Modules for OSGi Service Platforms” book
2. Spring Dynamic Modules reference manual: http://static.springframework.org/osgi/docs/1.2.0/reference/pdf/spring-dm-reference.pdf

Spring Dynamic Modules is not much coding. It is all about writing configuration files. Mainly there are two files

1. modulename-context.xml
2. modulename-osgi-context.xml

Rest is in the book and reference manual.

Note: Dont get confused with Spring DM and Spring DM Server.
Spring DM means Spring Dynamic Modules
Spring DM Server supports deployment of Spring DM Modules and standard J2EE jar/war files.
When we are working in OSGi environment we dont need Spring DM Server.


#osgi, #spring-dm, #spring-dynamic-modules