Category Archives: Spring

Microservices – Full-fledged project using Spring Framework

As part of Microservices Hackathon (a technical hackathon), was fortunate enough to work with some like minded folks and with the help of an existing project in Github, was able to create and extend a full-fledged microservices based project using Spring Boot, Spring Cloud and obviously Netflix-OSS.

The project can be found in the below link location:

Let me know your comments on this.

Page Visitors: 259

Spring Book – Chapter 14 – Spring MVC and Spring Web Flow

Disclaimer: The chapter have been written with figures sourced from various on-line materials. I haven’t been bale to attribute these figures with source. Really apologize for this. In case anyone has any issues in me using the figures and content, please drop an email to me at I will make sure that the details are either attributed or the image/content removed from my blog post. Thanks in advance.

Spring Framework’s web application support is through two sub-projects namely Spring MVC and Spring Web Flow.

Spring Framework has its own MVC based web application framework in the form of Spring MVC. They conceived and developed its web framework to address some of the deficiencies and poor design consideration in other popular framework available in the market. One of the main deficiencies identified was the lack of separation of concerns like proper separation between the presentation and request handling layer and between request handling layer and the model layer. Similar to Struts, Spring MVC is a request-based web application framework. Spring MVC makes sure that all the interfaces are tightly coupled with the core Servlet API’s rather than the Spring API’s.

Spring Web Flow is one of the sub-project which aims at providing the infrastructure for developing and running web application. It tries to aid web application developers in defining appropriate navigation rules, manage navigation and conversational state as well as facilitating high level reuse and modularization.

Spring MVC as well as Spring Web Flow is a very huge topic to cover in one Chapter. There are books written only on these topics. I would cover some basic concepts of both Spring MVC and Spring Web Flow in this Chapter. The first part of this Chapter makes you walk through Spring MVC and the second part of this Chapter walks through Spring Web Flow. I will try to cover basic detail of both frameworks so that you will get a heads up on these and can start off developing using these.

Spring MVC

Spring MVC allows you to build extensible, robust and loosely coupled MVC-based web application. With the use of the famous Model-View-Controller pattern, it inherently brings separation of the various layers in a typical web application namely business, presentation and navigation in a clear way.

We have covered MVC pattern in detail in this book, but just to refresh your mind, the responsibility of Model is to encapsulate the application data, the responsibility of View is to render the response to the user with the help from the Model object and the responsibility of Controller is to receive the request from the end user and transfer it to the back-end services which will populate the Model objects and sends the view object to the user.

Spring MVC's fit in an enterprise application containing other layers

Figure 14-1. Spring MVC’s fit in an enterprise application containing other layers

Page Visitors: 3625

Spring Framework Vs. JEE – Part III

This is my final blog on this topic, hopefully. Part I of the blog can be found in here and Part II of this blog can be found in here.

I do at times think that my blog title itself is misleading or rather incorrect as I don’t feel that there needs to be a comparison between the two as both can exists together in one application without any issues at all. In fact if that’s the case we can use the best of both and be happy. But, there does exist this debate for a very long time and now a days Oracle also at times gives a comment to kill Spring Framework (buy and kill it to reduce competition, Oracle’s buying spree logic) and go with standards. Being the creators and maintainers of the Java language they do have the right to promote JEE but I feel they don’t have to have such a stance IMHO.

The community with full adoption of language has made it to a be a standard. Similarly when Spring Framework came in existence it was indeed helping Java developers use Java and avoid the complexities to develop enterprise application. In fact we have to give full credit to Spring Framework in keeping Java language alive and kicking. I have heard many times, even from my own managers that Java is too heavy and not that good for application development when you compare .NET. Spring to some extent have been bale to bring that easiness to it by taking the complexities away. At the moment also there might not be that much comparison between easiness with respect to .NET, but community is ready to develop applications using Java. Again for enterprise application comparing .NET and Java (JEE) is not that of a good idea because of so many reasons. Don’t want to divulge too much off the topic here.

As Kelly Tisdell mentions in his blog, JEE has definitely taken some page out of Spring Book and added onto its big Java bible and spreads a word across that “Java is standard, so migrate to JEE from Spring to be in standard”. It doesn’t say directly that stop using Spring but it has that tone in it.

Even after taking those pages, to develop an enterprise application from scratch using JEE does have its won complexities and Spring does have that easiness to it (might be subjective and debatable, but that what i feel). Most of nicer features in Spring has now crept into JEE under different names and much refined fashion (JEE have learned from mistakes and corrected it) for sure and that’s the reason developers have been prompted to think for this migration.

I wanted to put more facts in here rather than my opinions, but after so long I have indeed lost interest in filling in more details and i thought that i will just give my opinion and close this not so ending blog post.  Apologies for same.

In my opinion, Spring and JEE should marry each other and an enterprise application should be developed taking into good points from both. I am in no way saying that JEE or Spring scores over the other because both are really good platforms to develop your enterprise applications.

Page Visitors: 240

Spring Book – Chapter 21 – Spring Batch

Spring Batch is the first Java based lightweight, comprehensive framework for batch processing. Being built on top of the Spring Framework, it gives all the advantages of productive, POJO-based development approach.

  • Spring Batch is a lightweight, comprehensive batch framework designed to enable the development of robust batch applications vital for the daily operations of enterprise systems. Spring Batch builds upon the productivity, POJO-based development approach, and general ease of use capabilities people have come to know from the Spring Framework, while making it easy for developers to access and leverage more advanced enterprise services when necessary.
  • – Spring batch documentation (

In this Chapter, we will cover Spring Batch in a comprehensive manner and aims at letting you use it in your enterprise application with less effort. The initial sections will introduce you to the core concepts on which Spring Batch is build and then later on delve deep into the various concepts in details along with appropriate code snippets.

Batch and Offline Processing

You would have heard these terms batch and offline processing for quite some time now and every time you have such requirement in your application you sit in front of the computer and start something fresh and code from scratch to realize this. With Spring Batch you now have a framework using which you can do these in a much better and cleaner manner. Before going through Spring Batch in detail, I would like to spend sometime explaining the usual business case which Spring Batch tries to achieve. Primary among these are batch and offline processing.

Batch Processing

Batch applications needs to process high volume of business critical transactional data in an efficient manner. A typical batch program does the following:

  • Reads a large amount of data from database, file or queue as the case may be.
  • Processes the data according to the business requirement in an efficient manner.
  • Writes back the modified/processed data to database, file or queue as the case may be.

Batch is a group of similar or identical items and the pseudo code for this can be shown in Figure 23-1 below.

 Figure 23-1. Pseudocode for a typical Batch

Figure 23-1. Pseudocode for a typical Batch

Offline Processing

In most modern day applications there requires capability processing client request in offline manner. Offline processing differs from online/real-time processing with respect to the following aspects as outlined below:

  • Processing of processes which are long-running and which occurs beyond usual office hours
  • Non-interactive in nature and often requires appropriate logic capable of handling errors and taking necessary actions like restart in some cases and so forth.
  • Processing of processes which have large amount of data not fitting into a single transaction.

Some of the common examples of batch and offline processing are as given below, so that you can understand the use of Spring Batch and appreciate what it delivers out-of-box for you.

  • Large scale output jobs which need to run on a timely manner. For example; sales report spanning whole month or even whole year.
  • Import/export handling of data. For example; ETL (Extract-Transform-Load) jobs, data synchronization jobs etc.
  • Various close of business jobs. For example; sales report spanning a day, business level reporting etc.
  • The lack of standard, reusable batch architecture has resulted in the proliferation of many one-off, in-house solutions developed within client enterprise IT functions.
  • – Spring batch documentation (

Why a framework?

So why would you need a framework for implementing batch? Why can’t we use a “for loop” for doing such batch jobs? We need to have a framework which addresses not only running a bunch of code in a loop fashion but also to have other features/capabilities/business scenarios as listed below (as detailed in Spring Batch documentation):

  • Commit batch processes periodically; Capability of committing the processed data at times due to various business reasons.
  • Staged, enterprise message-driven processing
  • Concurrent batch processing; parallel processing of a job
  • Massively parallel batch processing
  • Sequential processing of dependent steps with extensions to workflow-driven batches
  • Manual or scheduled restart after failure
  • Whole batch transaction: for cases with a small batch size or existing stored procedure s/scripts
  • Partial processing: skip records e.g. on rollback

Page Visitors: 17602

Spring Book – Chapter 20 – Spring Integration

Any modern application does not live in isolation. To realize the business requirements it has to communicate with customers of varied types and other applications in variety of ways. Application integration lets your application do this and in modern day applications, this is crucial for any application. Spring Integration aids in application integration that lets applications share data and services with each other making it connect with varied kind of users.

The Spring Integration is an open-source; simple integration framework that leverages the capabilities of widely adopted Spring Framework making application integration easy and simpler to implement.

This Chapter will help you start with Spring Integration and will aid you in achieving the various integration requirement in your application. I am sure after reading through this Chapter you will have one more weapon up your sleeves which you can use and reap benefits from its high level of integration capabilities.

Spring Integration Goals and Principles

Spring Integration is motivated by the following goals:

  • Provide a simple model for implementing complex enterprise integration solutions.
  • Facilitate asynchronous, message-driven behavior within a Spring-based application.
  • Promote intuitive, incremental adoption for existing Spring users.

Spring Integration is guided by the following principles:

  • Components should be loosely coupled for modularity and testability.
  • The framework should enforce separation of concerns between business logic and integration logic.
  • Extension points should be abstract in nature but within well-defined boundaries to promote reuse and portability.

The goals and principles of Spring Integration is as quoted in the Spring Integration Reference Manual.

Spring Integration Benefits

Spring Integration benefits can be summarized as follows:

  • Loose coupling between components – brings about development of small and focused components that caters to specific role and responsibility. This eases testing and promotes reuse largely.
  • Helps to separate integration and processing logic – Spring Integration pitches-in, handling message routing, transformation etc. and eases the application developer from this. Due to high level of configuration based integration style, easily processing can be switched between synchronous and asynchronous with no change in the code that is handy in this ever-changing business application scenario.
  • Promotes Event-driven architecture – No hard coded process flows and capability to easily change and expend these flows according to application requirement. Single word that can be used is adaptability.

Enterprise Integration Pattern (EIP)

Enterprise Integration Patterns is a book by Gregor Hohpe and Bobby Woolf and describes a number of design patterns for the use of enterprise application integration and message-oriented middleware. Enterprise Integration Patterns can be implemented without coding using Spring Integration or Apache Camel.

Enterprise application integration is an integration framework composed of a collection of technologies and services, which form a middleware to enable integration of systems and applications across the enterprise.


Spring Integration brings the power of Dependency Injection (DI) that Spring Framework is well known for and EIP patterns implementation together to nicely manage the resources and lets you focus on business logic rather than messaging infrastructure code.

Spring Integration Namespaces

For easing the various integration style configurations, Spring Integration has dedicated namespaces for each of them. Table 22-1 gives details of Spring Integration namespace in a tabular form for easy reading and understanding.

Table 22-1. Spring Integration namespaces

Namespace URL Prefix Description int Main schema file Defines the configuration elements for Spring Integration File Adapters. ftp Defines the configuration elements for Spring Integration FTP Adapters. http Defines the configuration elements for Spring Integration’s HTTP adapters. httpinvoker Defines the configuration elements for Spring Integration’s HttpInvoker adapters. NOTE: The http-invoker support is deprecated as of 2.0.x. It is recommended to use the REST-based HTTP adapters instead. xml Defines the configuration elements for Spring Integration’s XML support. jms Defines the configuration elements for Spring Integration’s JMS adapters. ip Defines the configuration elements for Spring Integration’s IP adapters. xmpp twitter event Defines the configuration elements for Spring Integration Event Adapters. gemfire Defines the core configuration elements for Spring Integration GemFire Support. groovy jdbc Defines the configuration elements for Spring Integration’s JDBC components. jmx Defines the configuration elements for Spring Integration’s JMX adapters. mail Defines the configuration elements for Spring Integration’s Mail Channel Adapters. redis Defines the configuration elements for Spring Integration Redis Adapters and Channels. rmi Defines the configuration elements for Spring Integration’s RMI adapters. security sftp Defines the configuration elements for Spring Integration SFTP Adapters. stream Defines the configuration elements for Spring Integration Stream-based Channel Adapters. ws Defines the configuration elements for Spring Integration’s Web Service adapters.

Page Visitors: 9328

Spring Framework Vs. JEE – Part II

As promised this is my second part of my blog. The first part of the blog can be accessed from here.

As part writing this blog i browsed through various blogs on the same topic. As i told in my first blog, this really is a holy war and over coming few months and years, this will rage even harder.

I bust out into laugh after reading one of the blogs, the link for which is as given below:-

The point that i burst outlaughing when the author stated as below:-


…… Java EE 5 took a few pages out of Spring’s book and simplified the development of enterprise components with…….


Yes, JEE sure did take some very crucial and important pages out of Spring book and because of which it is becoming superior day-by-day if not by huge margin. Spring with full support from its community is not far behind and with foundation in place, its building up components one after another. Its also adding in more and more support for open source libraries with ever growing sub-projects under the Spring Framework umbrella.

Also now its is slowly becoming a norm when considering a new open source for development to see how strongly it can be integrated into Spring and how seamless Spring configurations can be used. In my web service framework comparison, you wouldn’t believe, this was considered as one of the requirements and it will be a bonus for any open source to state that “they can be integrated into Spring” with some few lines of Java or XML configuration.

Spring has an edge by keeping it open for good open source libraries to plug on at any time and replace these libraries with a new one by mere configurations (at-least theoretically possible… :)). Java theoretically is “Write once run anywhere”, but is it truly that easy for a a production application to move from one environment to a new one… Hmmm… I don’t think so… 🙂

I am sort of exhausted already writing this blog. I will have to put you all in some suspense and put everything else that i plan to write in a new blog part. Hold on tight and i am sure i wouldn’t make you unhappy. Expect third part in another 3 days time. Its weekend here and i am really looking forward to it in a big way.

Page Visitors: 309

Spring Framework Vs. JEE – Part I

Am I playing with fire here. Perhaps Yes.

As many say, this truly classify itself to be a holy war for predominance and will surely stir some dirty stuff out into the air.

One of my colleagues recently came to me and had a small debate as to why the our organization selected Spring over JEE. He was very much in favor of JEE especially JEE 6.

We sometime back (more than an year) had an exercise in which the task was to choose organization wide Java framework. As you guessed right, we did have Spring Framework and JEE as strong candidates. Our approach was really methodical and a methodology which was devised internal to the organization was used.

In this methodology the two candidates was put into test. First of all, various architecture quality attributes were put in such as Performance, Scalability, Testability etc. and then various requirements in these attributes were classified/grouped together. Once we have that, we get the various stakeholders involved and get their buy in and their stand on the overall acceptance of these quality attributes and rank it. We then went on with POC (Proof of Concept) and each requirement was rated against each of the chosen frameworks.

Finally after a grueling exercise of rating various requirement for each of the framework, a final rating comes out which give good indication as to which on quality attributes gets favored for each of the framework and according to the stakeholders, which one to choose out of these two. The choice was made and there was no surprise, it was Spring Framework.

For our company now the chosen default framework is Spring and anything else if it is taken, it goes as an exception.

For me when i say that i use Spring Framework, it doesn’t in any way mean that i don’t use JEE. They cannot be mutually exclusive, rather when combined together, it gives immense advantage to the project that you are developing. We do use Spring as our choice of framework but haven’t just taken out JEE in any sense out of the window, rather when the right time comes another evaluation as detailed above will be done to asses the situation even further. Till that time i feel choosing Spring as the default framework is a good one in all aspects.

In my next blog (Click here), I would try to give some of the major points, which made us choose Spring as a default framework of choice for developing any application within the organization.

Earlier i have done couple of comparisons as detailed below:-

Spring Integration Vs. Apache Camel

Web Service Framework Comparison – 2013 – Part I

Web Service Framework Comparison – 2013 – Part II

Page Visitors: 786