- Spring Boot - Google OAuth2 Sign-In
- Spring Boot - Google Cloud Platform
- Spring Boot - OAuth2 with JWT
- Securing Web Applications
- Spring Boot - Database Handling
- Rest Controller Unit Test
- Spring Boot - Unit Test Cases
- Spring Boot - Twilio
- Spring Boot - Apache Kafka
- Spring Boot - Batch Service
- Spring Boot - Web Socket
- Spring Boot - Hystrix
- Spring Boot - Sending Email
- Spring Boot - Flyway Database
- Tracing Micro Service Logs
- Spring Boot - Creating Docker Image
- Spring Boot - Enabling Swagger2
- Spring Boot - Admin Client
- Spring Boot - Admin Server
- Spring Boot - Actuator
- Spring Cloud Configuration Client
- Spring Cloud Configuration Server
- Zuul Proxy Server and Routing
- Service Registration with Eureka
- Spring Boot - Eureka Server
- Spring Boot - Enabling HTTPS
- Spring Boot - Scheduling
- Spring Boot - Internationalization
- Spring Boot - CORS Support
- Consuming RESTful Web Services
- Spring Boot - Thymeleaf
- Spring Boot - Service Components
- Spring Boot - File Handling
- Spring Boot - Rest Template
- Spring Boot - Tomcat Port Number
- Spring Boot - Servlet Filter
- Spring Boot - Interceptor
- Spring Boot - Exception Handling
- Building RESTful Web Services
- Spring Boot - Logging
- Spring Boot - Application Properties
- Spring Boot - Runners
- Spring Beans & Dependency Injection
- Spring Boot - Code Structure
- Spring Boot - Build Systems
- Spring Boot - Tomcat Deployment
- Spring Boot - Bootstrapping
- Spring Boot - Quick Start
- Spring Boot - Introduction
- Spring Boot - Home
Spring Boot Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Spring Boot - Runners
Apppcation Runner and Command Line Runner interfaces lets you to execute the code after the Spring Boot apppcation is started. You can use these interfaces to perform any actions immediately after the apppcation has started. This chapter talks about them in detail.
Apppcation Runner
Apppcation Runner is an interface used to execute the code after the Spring Boot apppcation started. The example given below shows how to implement the Apppcation Runner interface on the main class file.
package com.tutorialspoint.demo; import org.springframework.boot.ApppcationArguments; import org.springframework.boot.ApppcationRunner; import org.springframework.boot.SpringApppcation; import org.springframework.boot.autoconfigure.SpringBootApppcation; @SpringBootApppcation pubpc class DemoApppcation implements ApppcationRunner { pubpc static void main(String[] args) { SpringApppcation.run(DemoApppcation.class, args); } @Override pubpc void run(ApppcationArguments arg0) throws Exception { System.out.println("Hello World from Apppcation Runner"); } }
Now, if you observe the console window below Hello World from Apppcation Runner, the println statement is executed after the Tomcat started. Is the following screenshot relevant?
Command Line Runner
Command Line Runner is an interface. It is used to execute the code after the Spring Boot apppcation started. The example given below shows how to implement the Command Line Runner interface on the main class file.
package com.tutorialspoint.demo; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApppcation; import org.springframework.boot.autoconfigure.SpringBootApppcation; @SpringBootApppcation pubpc class DemoApppcation implements CommandLineRunner { pubpc static void main(String[] args) { SpringApppcation.run(DemoApppcation.class, args); } @Override pubpc void run(String... arg0) throws Exception { System.out.println("Hello world from Command Line Runner"); } }
Look at the console window below “Hello world from Command Line Runner” println statement is executed after the Tomcat started.
Advertisements