|
@@ -2,23 +2,32 @@ package hello;
|
2
|
2
|
|
3
|
3
|
import java.util.Arrays;
|
4
|
4
|
|
|
5
|
+import org.springframework.boot.CommandLineRunner;
|
5
|
6
|
import org.springframework.boot.SpringApplication;
|
6
|
7
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
7
|
8
|
import org.springframework.context.ApplicationContext;
|
|
9
|
+import org.springframework.context.annotation.Bean;
|
8
|
10
|
|
9
|
11
|
@SpringBootApplication
|
10
|
12
|
public class Application {
|
11
|
|
-
|
|
13
|
+
|
12
|
14
|
public static void main(String[] args) {
|
13
|
|
- ApplicationContext ctx = SpringApplication.run(Application.class, args);
|
14
|
|
-
|
15
|
|
- System.out.println("Let's inspect the beans provided by Spring Boot:");
|
16
|
|
-
|
17
|
|
- String[] beanNames = ctx.getBeanDefinitionNames();
|
18
|
|
- Arrays.sort(beanNames);
|
19
|
|
- for (String beanName : beanNames) {
|
20
|
|
- System.out.println(beanName);
|
21
|
|
- }
|
|
15
|
+ SpringApplication.run(Application.class, args);
|
|
16
|
+ }
|
|
17
|
+
|
|
18
|
+ @Bean//It retrieves all the beans
|
|
19
|
+ public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
|
|
20
|
+ return args -> {
|
|
21
|
+
|
|
22
|
+ System.out.println("Let's inspect the beans provided by Spring Boot:");
|
|
23
|
+
|
|
24
|
+ String[] beanNames = ctx.getBeanDefinitionNames();
|
|
25
|
+ Arrays.sort(beanNames);
|
|
26
|
+ for (String beanName : beanNames) {
|
|
27
|
+ System.out.println(beanName);
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ };
|
22
|
31
|
}
|
23
|
32
|
|
24
|
33
|
}
|