File tree 1 file changed +38
-0
lines changed
spring-boot/src/main/java/com/baeldung/springbootnonwebapp
1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
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 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 FINISHED" );
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 ("EXECUTING : command line runner" );
34
+ for (int i = 0 ; i < args .length ; ++i ) {
35
+ LOG .info ("args[{}]: {}" , i , args [i ]);
36
+ }
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments