Aleena Rose-Mathew 6 years ago
parent
commit
03476cb47b

+ 19
- 10
initial/src/main/java/hello/Application.java View File

@@ -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
 }

+ 4
- 3
initial/src/main/java/hello/HelloController.java View File

@@ -3,11 +3,12 @@ package hello;
3 3
 import org.springframework.web.bind.annotation.RestController;
4 4
 import org.springframework.web.bind.annotation.RequestMapping;
5 5
 
6
-@RestController
6
+@RestController//meaning it's ready for use by Spring MVC to handle web requests.
7 7
 public class HelloController {
8 8
     
9
-    @RequestMapping("/")
10
-    public String index() {
9
+    @RequestMapping("/greeting")//to invoke index method
10
+    public String index()
11
+    {
11 12
         return "Greetings from Spring Boot!";
12 13
     }
13 14