The concept of the scope of a bean in spring enables us to focus on business logic without having to worry about data inconsistency.

The lifespan of beans in a spring application are defined with respect to the application context(@Singleton), thread (@Prototype), or incase of web-aware applications http session (@Session), http request (@Request) or servlet lifecycle (@ApplicationScope), webSocket session.

In other words, a bean annotated with @Singelton will be created once when the container is initialized (Application is started) and is destroyed when the container is terminated (Application is shut down).

Similarly, a bean annotated with @prototype is created every…

MultiThreading in SpringBatch

Spring Batch jobs allow us to perform non-interactive bulk processing. Additionally, it also provides both synchronous and asynchronous processing.

As SpringBatch jobs usually involve processing huge blocks of data making their execution asynchronous might be a good idea unless sequential processing is essential.

This can be done in two ways.

· By making the processing of data within a given step asynchronous

· By making the job asynchronous i.e asynchronously execution of steps

Asynchronous Step

The processing of data within a step can be made asynchronous by specifying a task executor in step configuration.

Spring facilitates request validation by means of Spring Validation which enables us to bind a validator to a controller.

With Spring based validations the validator for a controller is specified by annotating the method which accepts an argument of type WebDataBinder and a void return type with @Initbinder in the controller.

There are two types of constraint validations that can be used to warrant that a model class abides by the said constraints.

·Field level validation using Spring validator

· Class level validation using Spring validator

Both these approaches have their own distinct set of advantages.

Field-level validation using spring validator

Spring Validation enables us to define our own custom constraints. One way of doing this is by creating annotations.

The fields of the model classes are then to be annotated with these annotations to ensure they abide by the said constraints.

The salient feature of this approach is that these annotations can be reused on…


A full stack developer with an unquenchable thirst for coffee and anything programming :)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store