Spring Boot CommandLineRunner and ApplicationRunner

Whenever you need, to perform a specific task once after all the Spring Beans are created and the Application Context has been created then you can implement ApplicationRunner or CommandLineRunner interface. Both the interfaces works the same way and has a single run() method. A similar implementation is already there in Spring and many people would have known it JobLauncherCommandLineRunner which is used for running jobs in Spring Batch. [Read more…]

How to Create Deployable WAR | Spring Boot | SpringBootServletInitializer

Previously we have learnt how to build a Spring Boot Hello World application using Maven and through Eclipse. In this Spring Boot example we will be building the same hello world application with a slight difference instead of building a executable JAR we will be be building a WAR file. We will be extending SpringBootServletInitializer in order to create deployable WAR file. [Read more…]

Spring Security Tutorial Hello World Example – Using XML Configuration

In this Spring Security Tutorial, we will build a Simple Spring MVC Hello World application integrated with Spring Security features. In this application, we will be dealing with two major security areas Authentication and Authorization.

  • Authentication – It is nothing but validating whether the user is a valid user or not.
  • Authorization –  Deciding whether the particular user is allowed to perform a certain activity in the application or not.

[Read more…]

ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

When you happen to work with a Spring MVC Framework based Web application. Then java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener is a common problem which will be occurring during deployment. Spring MVC throws this exception when it is not able to find the “org.springframework.web.context.ContextLoaderListener” class which loads up the all the Spring MVC configuration files and other configuration files which is declared in the web.xml.



This exception will mostly happen when you start the server [Read more…]

Spring PropertyPlaceholderConfigurer Example – Reading a Property File

It’s never a good practice to hard code and combine any environment related details such a username, password or file path etc. along with spring bean configuration. Usually in Java we will be having those details written in a separate property file and it will be read during the execution, the same can be followed in the spring as well using PropertyPlaceholderConfigurer.

Spring comes with a bean factory post processor called PropertyPlaceholderConfigurer which allows you to externalize those details into a properties file. In this Spring PropertyPlaceholderConfigurer Example we will learn how to use the PropertyPlaceholderConfigurer. [Read more…]

Spring Bean Creation – Static Factory Method & Instance Factory Method

In Spring we can create bean using Spring FactoryBean, FactoryBean is an interface and we need to give implementations for the methods in it. If you don’t want to go by that methodology but still want Java Factory Pattern to be implemented then we can go for Static Factory Method and Instance Factory Method.

The client who requests for an object can simply make a call to the factory method which we have defined without knowing about the creation detail. We will be using factory-method and factory-bean attribute in our configuration for the Injection of Bean, through the below spring factory pattern example lets learn more about it. [Read more…]

Spring Bean Life Cycle – Bean Initialization and Destruction

Spring IoC container is also responsible for managing the Spring Bean Life Cycle, the life cycle of beans consist of call back methods such as Post initialization call back method and Pre destruction call back method. Below steps are followed by Spring IoC Container to manage bean life cycle.

Spring Bean Life Cycle

  1. Creation of bean instance by a factory method.
  2. Set the values and bean references to the bean properties.
  3. Call the initialization call back method.
  4. Bean is ready for use.
  5. Call the destruction call back method.

[Read more…]