~~ Spring Boot ~~

 1. Introduction

    1.1 Spring Boot-Intorduction
    1.2 Spring Boot-Architecture
    1.2 Spring Boot-Quick Start

 2. Project Creation

    2.1 Spring Initializer
    2.2 Spring Boot CLI
    2.3 STS IDE
    2.4 Eclipse IDE
    2.5 First Program
    2.6 Spring Boot-Code Structure

 3. Spring Boot – Beans & DI
 4. Spring Boot – Runners
 5. Spring Boot – Properties File
 6. Spring Boot – Looging
 7. Spring Boot – Rest WebServices
 8. Spring Boot – Exception Handling
 9. Spring Boot – Interceptor
 10. Spring Boot – Servlet Filter
 11. Spring Boot – Rest Template
 12. Spring Boot – File HANDLING
 13. Spring Boot – Thymeleaf
 14. Spring Boot – Internationalization
 15. Spring Boot – Scheduling
 16. Spring Boot – Actuator
 17. Spring Boot – Email Handling
 18. Spring Boot – Database Handling
 19. Spring Boot – Caching

Spring Boot | Runner :

In Spring Boot when we want to execute some custom code immediatelly after our Spring Boot application start. We can achive this using Runner”. It will execute only once in application lifetime. Here we have 2 types of Runners, which we can use.

  1. Application Runner
  2. CommandLine Runner

 

1. Application Runner :

Application Runner is an interface used to execute some custom code immediately after Spring Boot application start.

Here we need to implement ApplicationRunner interface and overide run method as below.

Example :

package com.study4online;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class RunnersApplication implements ApplicationRunner {

public static void main(String[] args) {
SpringApplication.run(RunnersApplication.class, args);
}

@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("Hello World From Application Runner !!!");
}

}
Application Runner

Now if we observe we can see in above Output screenshot of console window, our message “Hello World From Application Runner !!!” gets printed immediatelly after the server started.

2. CommandLine Runner :

CommandLine Runner is an interface same as Application Runner, which which execute our code immediately after Server start.

Here we need to implement “CommandLine Runner” interface and overide run method as below.Let’s see how we can implement CommandLine.

package com.study4online;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class RunnersApplication implements CommandLineRunner {

public static void main(String[] args) {
SpringApplication.run(RunnersApplication.class, args);
}

@Override
public void run(String... arg0) throws Exception {
System.out.println("Hello world from Command Line Runner !!!");
}
}
CommandLine Runner

Now if we observe we can see in above Output screenshot of console window, our message “Hello world from Command Line Runner !!!” gets printed immediately after the server started.

Help Others, Please Share