Просмотр исходного кода

Make edits based on Bev's feedback

Greg Turnquist 13 лет назад
Родитель
Сommit
221145cfec
2 измененных файлов: 69 добавлений и 48 удалений
  1. 17
    7
      README.ftl.md
  2. 52
    41
      README.md

+ 17
- 7
README.ftl.md Просмотреть файл

@@ -35,13 +35,15 @@ For example:
35 35
 - Got Spring MVC? There are several specific beans you almost always need, and Spring Boot adds them automatically. A Spring MVC app also needs a servlet container, so Spring Boot automatically configures embedded Tomcat.
36 36
 - Got Jetty? If so, you probably do NOT want Tomcat, but instead embedded Jetty. Spring Boot handles that for you.
37 37
 - Got Thymeleaf? There are a few beans that must always be added to your application context; Spring Boot adds them for you.
38
-- Doing multipart file uploads? [MultipartConfigElement](http://docs.oracle.com/javaee/6/api/javax/servlet/MultipartConfigElement.html) is part of the servlet 3.0 spec and lets you define upload parameters in pure Java. With Spring Boot, you don't have to plug that into your servlet. Define one in your application context and Spring Boot will plug it into Spring MVC's battle-tested `DispatcherServlet`.
38
+- Doing multipart file uploads? [MultipartConfigElement](http://docs.oracle.com/javaee/6/api/javax/servlet/MultipartConfigElement.html) is part of the servlet 3.0 spec and lets you define upload parameters in pure Java. With Spring Boot, you don't have to plug a MultipartConfigElement into your servlet. Just define one in your application context and Spring Boot will plug it into Spring MVC's battle-tested `DispatcherServlet`.
39 39
 
40
-These are just a few examples of the automatic configuration Spring Boot provides. At the same time, Spring Boot doesn't get in your way. For example, Spring Boot may make assumptions and add a `SpringTemplateEngine` for your Thymeleaf-based application, unless you've already defined one. At that point, Spring Boot automatically steps aside and lets you take control.
40
+These are just a few examples of the automatic configuration Spring Boot provides. At the same time, Spring Boot doesn't get in your way. For example, if Thymeleaf is on your path, Spring Boot adds a `SpringTemplateEngine` to your application context automatically. But if you define your own `SpringTemplateEnginer` with your own settings, then Spring Boot won't add one. This leaves you in control with little effort on your part.
41
+
42
+> **Note:** Spring Boot doesn't generate code or make edits to your files. Instead, when you start up your application, Spring Boot dynamically wires up beans and settings and applies them to your application context.
41 43
 
42 44
 Create a simple web application
43 45
 ---------------------------------
44
-You already have the base build file at the top. Now you can create a web controller for a simple web application.
46
+Now you can create a web controller for a simple web application.
45 47
 
46 48
     <@snippet path="src/main/java/hello/HelloController.java" prefix="initial"/>
47 49
     
@@ -121,7 +123,7 @@ Greetings from Spring Boot!
121 123
 
122 124
 Switch from Tomcat to Jetty
123 125
 ---------------------------
124
-Jetty and Tomcat are both compliant servlet containers, so it's easy to switch.
126
+What if you prefer Jetty over Tomcat? Jetty and Tomcat are both compliant servlet containers, so it should be easy to switch. With Spring Boot, it is!
125 127
 
126 128
 Add this to your build file's list of dependencies:
127 129
 
@@ -134,7 +136,7 @@ Add this to your build file's list of dependencies:
134 136
 
135 137
 Add multipart upload support
136 138
 -------------------------------
137
-Suppose you want to add file upload support. To do that, update your configuration and add a `MultipartConfigElement` to the application context.
139
+Suppose you want to add file upload support. To do that, update your configuration by adding a `MultipartConfigElement` to the application context.
138 140
 
139 141
     <@snippet path="src/main/java/hello/Application.java" prefix="complete"/>
140 142
     
@@ -149,7 +151,7 @@ Run the app again:
149 151
 $ mvn package spring-boot:run
150 152
 ```
151 153
 
152
-Now check the output:
154
+Now check out the output:
153 155
 
154 156
 ```sh
155 157
 Let's inspect the beans provided by Spring Boot:
@@ -251,6 +253,8 @@ The response shows that shutdown through REST is currently disabled by default:
251 253
 {"message":"Shutdown not enabled, sorry."}
252 254
 ```
253 255
 
256
+Whew! You probably don't want that until you are ready to turn on proper security settings, it at all.
257
+
254 258
 For more details about each of these REST points and how you can tune their settings with an ``application.properties` file, check out the [Spring Boot][spring-boot] project.
255 259
 
256 260
 View Spring Boot's starters
@@ -276,7 +280,7 @@ But Spring Boot does yet more. It supports not only traditional WAR file deploym
276 280
 
277 281
 On top of that, Spring Boot also has Groovy support, allowing you to build web apps with as little as a single file.
278 282
 
279
-Put the following code inside **app.groovy**:
283
+Create a new file called **app.groovy** and put the following code in it:
280 284
 
281 285
 ```groovy
282 286
 @Controller
@@ -291,12 +295,18 @@ class ThisWillActuallyRun {
291 295
 }
292 296
 ```
293 297
 
298
+> **Note:** It doesn't matter where the file is.
299
+
294 300
 Next, [install Spring Boot's CLI](https://github.com/SpringSource/spring-boot#installing-the-cli).
295 301
 
296 302
 Run it as follows:
297 303
 
298 304
 ```sh
299 305
 $ spring run app.groovy
306
+```
307
+
308
+From a different terminal window:
309
+```sh
300 310
 $ curl localhost:8080
301 311
 Hello World!
302 312
 ```

+ 52
- 41
README.md Просмотреть файл

@@ -2,7 +2,7 @@
2 2
 What you'll build
3 3
 -----------------
4 4
 
5
-This guide provides an introduction to [Spring Boot][spring-boot] by building a simple web application. This doesn't demonstrate all of its features but will help you get started with the concepts Spring Boot has to offer.
5
+This guide walks you through the process of building a simple web application with [Spring Boot][spring-boot]. The guide provides a sampling of how Spring Boot helps you accelerate and facilitate app development. As you read more Spring getting started guides, you will see more use cases for Spring Boot.
6 6
 
7 7
 What you'll need
8 8
 ----------------
@@ -15,7 +15,6 @@ What you'll need
15 15
 [jdk]: http://www.oracle.com/technetwork/java/javase/downloads/index.html
16 16
 [mvn]: http://maven.apache.org/download.cgi
17 17
 
18
-
19 18
 How to complete this guide
20 19
 --------------------------
21 20
 
@@ -28,7 +27,7 @@ To **skip the basics**, do the following:
28 27
  - [Download][zip] and unzip the source repository for this guide, or clone it using [git](/understanding/git):
29 28
 `git clone https://github.com/springframework-meta/gs-spring-boot.git`
30 29
  - cd into `gs-spring-boot/initial`.
31
- - Jump ahead to [Warming up with Spring Boot](#initial).
30
+ - Jump ahead to [Learn what you can do with Spring Boot](#initial).
32 31
 
33 32
 **When you're finished**, you can check your results against the code in `gs-spring-boot/complete`.
34 33
 [zip]: https://github.com/springframework-meta/gs-spring-boot/archive/master.zip
@@ -105,22 +104,24 @@ In a project directory of your choosing, create the following subdirectory struc
105 104
 </project>
106 105
 ```
107 106
 
108
-Warming up with Spring Boot
109
----------------------------
107
+Learn what you can do with Spring Boot
108
+--------------------------------------
110 109
 
111
-What does Spring Boot provide? At the core, it offers a much faster way to build applications because it make reasonable assumptions such as looking at your classpath and other beans you have configured to see what you're missing.
110
+Spring Boot offers a fast way to build applications. It looks at your classpath and at beans you have configured, makes reasonable assumptions about what you're missing, and adds it. With Spring Boot you can focus more on business features and less on infrastructure.
112 111
 
113 112
 For example:
114
-- Got Spring MVC? There are a handful of needed beans people almost always use in that situation. Spring Boot adds them automatically. But why stop there? A Spring MVC app needs a servlet container so Spring Boot automatically configures embedded Tomcat.
115
-- Got Jetty? You probably do NOT want Tomcat, but instead embedded Jetty. Don't lift a finger; Spring Boot handles it for you.
116
-- Got Thymeleaf? There are a few beans that must always be added to your application context. Why should you have to deal with that? Let Spring Boot handle it for you.
117
-- Doing multipart file uploads? The [MultipartConfigElement](http://docs.oracle.com/javaee/6/api/javax/servlet/MultipartConfigElement.html) is part of the servlet 3.0 spec and let's you define upload parameters in pure Java. Why should you have to worry about plugging that into your servlet? Define one in your application context and Spring Boot will snatch it up and plug it into Spring MVC's battle tested `DispatcherServlet`.
113
+- Got Spring MVC? There are several specific beans you almost always need, and Spring Boot adds them automatically. A Spring MVC app also needs a servlet container, so Spring Boot automatically configures embedded Tomcat.
114
+- Got Jetty? If so, you probably do NOT want Tomcat, but instead embedded Jetty. Spring Boot handles that for you.
115
+- Got Thymeleaf? There are a few beans that must always be added to your application context; Spring Boot adds them for you.
116
+- Doing multipart file uploads? [MultipartConfigElement](http://docs.oracle.com/javaee/6/api/javax/servlet/MultipartConfigElement.html) is part of the servlet 3.0 spec and lets you define upload parameters in pure Java. With Spring Boot, you don't have to plug a MultipartConfigElement into your servlet. Just define one in your application context and Spring Boot will plug it into Spring MVC's battle-tested `DispatcherServlet`.
118 117
 
119
-It doesn't stop there. These are just a few examples of the automatic configuration provided by Spring Boot. But it doesn't get in your way. For example, Spring Boot may make assumptions and add a `SpringTemplateEngine` for your Thymeleaf-based application, unless you've already defined one. At that point, Spring Boot automatically steps aside and lets you take control.
118
+These are just a few examples of the automatic configuration Spring Boot provides. At the same time, Spring Boot doesn't get in your way. For example, if Thymeleaf is on your path, Spring Boot adds a `SpringTemplateEngine` to your application context automatically. But if you define your own `SpringTemplateEnginer` with your own settings, then Spring Boot won't add one. This leaves you in control with little effort on your part.
120 119
 
121
-Creating a simple web application
120
+> **Note:** Spring Boot doesn't generate code or make edits to your files. Instead, when you start up your application, Spring Boot dynamically wires up beans and settings and applies them to your application context.
121
+
122
+Create a simple web application
122 123
 ---------------------------------
123
-You already have the base build file at the top. Next step is to create a web controller for a simple web application.
124
+Now you can create a web controller for a simple web application.
124 125
 
125 126
 `src/main/java/hello/HelloController.java`
126 127
 ```java
@@ -141,9 +142,11 @@ public class HelloController {
141 142
 }
142 143
 ```
143 144
     
144
-The class is flagged as a `@Controller` meaning it's ready for use by Spring MVC to handle web requests. `@RequestMapping` maps `/` to the `index()` method. When invoked from a browser or using curl on the command line, it returns pure text thanks to the `@ResponseBody` annotation.
145
+The class is flagged as a `@Controller`, meaning it's ready for use by Spring MVC to handle web requests. `@RequestMapping` maps `/` to the `index()` method. When invoked from a browser or using curl on the command line, the method returns pure text thanks to the `@ResponseBody` annotation.
145 146
 
146
-To make it executable, create an `Application` class:
147
+Create an Application class
148
+---------------------------
149
+Here you create an `Application` class with the components:
147 150
 
148 151
 `src/main/java/hello/Application.java`
149 152
 ```java
@@ -180,7 +183,7 @@ public class Application {
180 183
 ```
181 184
     
182 185
 - `@Configuration` tags the class as a source of bean definitions for the application context.
183
-- `@EnableAutoConfiguration` tells Spring Boot to get going and start adding beans based on classpath settings, other beans, and various property settings.
186
+- `@EnableAutoConfiguration` tells Spring Boot to start adding beans based on classpath settings, other beans, and various property settings.
184 187
 - `@EnableWebMvc` signals Spring MVC that this application is a web application and to activate key behaviors such as setting up a `DispatcherServlet`.
185 188
 - `@ComponentScanning` tells Spring to look for other components, configurations, and services in the the `hello` package, allowing it to find the `HelloController`.
186 189
 
@@ -188,7 +191,9 @@ The `main()` method uses Spring Boot's `SpringApplication.run()` method to launc
188 191
 
189 192
 The `run()` method returns an `ApplicationContext` and this application then retrieves all the beans that were created either by your app or were automatically added thanks to Spring Boot. It sorts them and prints them out.
190 193
 
191
-To run it, execute:
194
+Run the application
195
+-------------------
196
+To run the application, execute:
192 197
 
193 198
 ```sh
194 199
 $ mvn package spring-boot:run
@@ -243,9 +248,9 @@ $ curl localhost:8080
243 248
 Greetings from Spring Boot!
244 249
 ```
245 250
 
246
-Switching to Jetty
247
-------------------
248
-What if you preferred Jetty over Tomcat? They're both compliant servlet containers, so it should be darn simple to switch. And it is!
251
+Switch from Tomcat to Jetty
252
+---------------------------
253
+What if you prefer Jetty over Tomcat? Jetty and Tomcat are both compliant servlet containers, so it should be easy to switch. With Spring Boot, it is!
249 254
 
250 255
 Add this to your build file's list of dependencies:
251 256
 
@@ -256,9 +261,9 @@ Add this to your build file's list of dependencies:
256 261
         </dependency>
257 262
 ```
258 263
 
259
-Adding multipart upload support
264
+Add multipart upload support
260 265
 -------------------------------
261
-Imagine you also want to add file upload support. To do that, update your configuration and add a `MultipartConfigElement` to the application context.
266
+Suppose you want to add file upload support. To do that, update your configuration by adding a `MultipartConfigElement` to the application context.
262 267
 
263 268
 `src/main/java/hello/Application.java`
264 269
 ```java
@@ -302,10 +307,10 @@ public class Application {
302 307
 }
303 308
 ```
304 309
     
305
-> **Note:** A production version of `MultipartConfigElement` would not be empty but instead specify things like target upload path, file size upload limits, etc.
310
+> **Note:** A production version of `MultipartConfigElement` would not be empty; it would specify target upload path, file size upload limits, and so forth.
306 311
 
307
-Re-run the app
308
---------------
312
+Re-run the application
313
+----------------------
309 314
 
310 315
 Run the app again:
311 316
 
@@ -356,15 +361,15 @@ simpleControllerHandlerAdapter
356 361
 viewControllerHandlerMapping
357 362
 ```
358 363
 
359
-There is little change from the previous output, except there is no longer a `tomcatEmbeddedServletContainerFactory`. Instead, there is a new `jettyEmbeddedServletContainer`. 
364
+Little changes from the previous output, except there is no longer a `tomcatEmbeddedServletContainerFactory`. Instead, there is a new `jettyEmbeddedServletContainer`. 
360 365
 
361 366
 There is also the `multipartConfigElement` you added. But along with it came a `multipartResolver` [courtesy of Spring Boot](https://github.com/SpringSource/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java), a bean recommended to support file uploads with Spring MVC.
362 367
 
363
-Other than that, everything else appears the same, as it should be. Most the beans listed above provide Spring MVC's production-grade features. Just swapping one part, the servlet container, and adding upload support shouldn't cause a system wide ripple.
368
+Otherwise, everything is the same, as it should be. Most beans listed above provide Spring MVC's production-grade features. Simply swapping one part, the servlet container, and adding upload support shouldn't cause a system-wide ripple.
364 369
 
365
-Adding consumer-grade services
370
+Add consumer-grade services
366 371
 ------------------------------
367
-If you are building a web site for your business, there are probably some management services you are thinking about adding. Spring Boot provides several out of the box with its [actuator module][spring-boot-actuator] like health, audits, beans, and more.
372
+If you are building a web site for your business, you probably need to add some management services. Spring Boot provides several out of the box with its [actuator module][spring-boot-actuator], such as health, audits, beans, and more.
368 373
 
369 374
 Add this to your pom.xml:
370 375
 ```xml
@@ -410,14 +415,16 @@ You can invoke shutdown through curl.
410 415
 $ curl -X POST localhost:8080/shutdown
411 416
 ```
412 417
 
413
-The response shows that shutdown through REST is currently disabled by default (thank goodness!):
418
+The response shows that shutdown through REST is currently disabled by default:
414 419
 ```sh
415 420
 {"message":"Shutdown not enabled, sorry."}
416 421
 ```
417 422
 
418
-For more details about each of these REST points and how you can tune their settings with an ``application.properties` file, feel free to dig into the [Spring Boot][spring-boot] project.
423
+Whew! You probably don't want that until you are ready to turn on proper security settings, it at all.
419 424
 
420
-Spring Boot's starters
425
+For more details about each of these REST points and how you can tune their settings with an ``application.properties` file, check out the [Spring Boot][spring-boot] project.
426
+
427
+View Spring Boot's starters
421 428
 ----------------------
422 429
 You have seen some of Spring Boot's **starters**. Here is a complete list:
423 430
 - spring-boot-starter-actuator
@@ -432,15 +439,15 @@ You have seen some of Spring Boot's **starters**. Here is a complete list:
432 439
 - spring-boot-starter-web
433 440
 
434 441
 
435
-That is not all
436
----------------
437
-That last example showed how Spring Boot makes it easy to wire beans you may not be aware you need. And it showed how to turn on convenient management services.
442
+JAR support and Groovy support
443
+------------------------------
444
+The last example showed how Spring Boot makes it easy to wire beans you may not be aware that you need. And it showed how to turn on convenient management services.
438 445
 
439 446
 But Spring Boot does yet more. It supports not only traditional WAR file deployments, but also makes it easy to put together executable JARs thanks to Spring Boot's loader module. The various guides demonstrate this dual support through the `spring-boot-maven-plugin`. 
440 447
 
441 448
 On top of that, Spring Boot also has Groovy support, allowing you to build web apps with as little as a single file.
442 449
 
443
-Put the following code inside **app.groovy**:
450
+Create a new file called **app.groovy** and put the following code in it:
444 451
 
445 452
 ```groovy
446 453
 @Controller
@@ -455,23 +462,27 @@ class ThisWillActuallyRun {
455 462
 }
456 463
 ```
457 464
 
465
+> **Note:** It doesn't matter where the file is.
466
+
458 467
 Next, [install Spring Boot's CLI](https://github.com/SpringSource/spring-boot#installing-the-cli).
459 468
 
460
-Finally, run it as follows:
469
+Run it as follows:
461 470
 
462 471
 ```sh
463 472
 $ spring run app.groovy
473
+```
474
+
475
+From a different terminal window:
476
+```sh
464 477
 $ curl localhost:8080
465 478
 Hello World!
466 479
 ```
467 480
 
468 481
 Spring Boot dynamically adds key annotations to your code and leverages [Groovy Grapes](http://groovy.codehaus.org/Grape) to pull down needed libraries to make the app run.
469 482
 
470
-Congratulations!
483
+Summary
471 484
 ----------------
472
-Spring Boot is powerful, but frankly too big to fit into a single guide. This is just a sampling of how much it can ramp up your development pace, letting you focus on business features and not worry about infrastructure.
473
-
474
-As you read more of this site's getting started guides, you will see it used all over the place. It might not be obvious at first, because Spring Boot is so good at adding the things you need without getting in your way. But after using it for a bit, you may wonder how you lived without it.
485
+Congratulations! You built a simple web application with Spring Boot and learned how it can ramp up your development pace. 
475 486
 
476 487
 [spring-boot]: https://github.com/SpringSource/spring-boot
477 488
 [spring-boot-actuator]: https://github.com/SpringSource/spring-boot/blob/master/spring-boot-actuator/README.md