Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.application.se2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.EventListener;
/**
* SpringBoot's main Application class containing Java's main() method with invocation
* and launch of Spring's run time.
*
* @author sgra64
*
*/
@SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan
public class Application {
/**
* Protected constructor for Spring Boot to create an Application instance.
* Application instances must be created by Spring, never by "new".
* @param args arguments passed from main()
*/
Application( String[] args ) {
System.out.println( "2. Hello SpringApplication, Constructor called." );
}
/**
* Entry point after Spring Boot has initialized the application instance.
*/
@EventListener(ApplicationReadyEvent.class)
public void doSomethingAfterStartup() {
System.out.println( "3. Hello SpringApplication, doSomethingAfterStartup() called." );
}
/**
* Java's main() method.
*
* @param args arguments passed from invoking command.
*/
public static void main( final String ... args ) {
System.out.println( "1. Hello SpringApplication!" );
System.out.print( " Initialize Spring Boot and create Application instance." );
// Initialize Spring Boot and create Application instance.
ApplicationContext applicationContext = SpringApplication.run( Application.class, args );
System.out.println( "4. Bye, SpringApplication, " + applicationContext.getId() + "!" );
}
/**
* Return the Application name.
*
* @return Application name.
*/
public String getName() {
return "se2-application";
}
}