Skip to content

Commit 400f86a

Browse files
author
hemant
committed
Removed 2 classes for main and other for Runner. Replaced them with a single class serving both the purposes
1 parent 98d37d0 commit 400f86a

File tree

3 files changed

+37
-44
lines changed

3 files changed

+37
-44
lines changed

spring-boot/src/main/java/com/baeldung/springbootnonwebapp/Runner.java

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.baeldung.springbootnonwebapp;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.boot.CommandLineRunner;
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
9+
/**
10+
* 1. Act as main class for spring boot application
11+
* 2. Also implements CommandLineRunner, so that code within run method
12+
* is executed before application startup but after all beans are effectively created
13+
* @author hemant
14+
*
15+
*/
16+
@SpringBootApplication
17+
public class SpringBootConsoleApplication implements CommandLineRunner {
18+
19+
private static final Logger LOG = LoggerFactory.getLogger(SpringBootConsoleApplication.class);
20+
21+
public static void main(String[] args) {
22+
LOG.info("STARTING THE APPLICATION");
23+
SpringApplication.run(SpringBootConsoleApplication.class, args);
24+
LOG.info("APPLICATION STARTED");
25+
}
26+
27+
/**
28+
* This method will be executed after the application context is loaded and
29+
* right before the Spring Application main method is completed.
30+
*/
31+
@Override
32+
public void run(String... args) throws Exception {
33+
LOG.info("START : command line runner");
34+
LOG.info("EXECUTING : command line runner");
35+
LOG.info("END : command line runner");
36+
}
37+
}

spring-boot/src/main/java/com/baeldung/springbootnonwebapp/SpringBootNonWebappApplication.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)