浏览代码

Merge ac63eed307fcff992c3178dd0079677fa00acd6a into 6899582c93bc19e5a13db2e66a6ef2fc6dcc8db4

Dong Li 8 年前
父节点
当前提交
fce7d66dde
没有帐户链接到提交者的电子邮件
共有 3 个文件被更改,包括 26 次插入20 次删除
  1. 2
    0
      initial/build.gradle
  2. 18
    13
      initial/src/main/java/hello/Application.java
  3. 6
    7
      initial/src/main/java/hello/HelloController.java

+ 2
- 0
initial/build.gradle 查看文件

@@ -27,5 +27,7 @@ targetCompatibility = 1.8
27 27
 dependencies {
28 28
     compile("org.springframework.boot:spring-boot-starter-web")
29 29
     testCompile("junit:junit")
30
+    testCompile("org.springframework.boot:spring-boot-starter-test")
30 31
 }
31 32
 
33
+

+ 18
- 13
initial/src/main/java/hello/Application.java 查看文件

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

+ 6
- 7
initial/src/main/java/hello/HelloController.java 查看文件

@@ -1,14 +1,13 @@
1 1
 package hello;
2 2
 
3
-import org.springframework.web.bind.annotation.RestController;
4 3
 import org.springframework.web.bind.annotation.RequestMapping;
4
+import org.springframework.web.bind.annotation.RestController;
5 5
 
6 6
 @RestController
7 7
 public class HelloController {
8
-    
9
-    @RequestMapping("/")
10
-    public String index() {
11
-        return "Greetings from Spring Boot!";
12
-    }
13
-    
8
+
9
+  @RequestMapping("/")
10
+  public String index() {
11
+    return "Greetings from Spring Boot!";
12
+  }
14 13
 }