Procházet zdrojové kódy

Edit and polish the guide

Greg Turnquist před 13 roky
rodič
revize
7fe82b6abf
2 změnil soubory, kde provedl 38 přidání a 36 odebrání
  1. 19
    18
      README.ftl.md
  2. 19
    18
      README.md

+ 19
- 18
README.ftl.md Zobrazit soubor

@@ -3,8 +3,7 @@
3 3
 What you'll build
4 4
 -----------------
5 5
 
6
-This guide provides an introduction to Spring Boot.
7
-
6
+This guide provides an introduction to 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.
8 7
 
9 8
 What you'll need
10 9
 ----------------
@@ -31,15 +30,15 @@ Set up the project
31 30
 Warming up with Spring Boot
32 31
 ---------------------------
33 32
 
34
-What does Spring Boot provide? At the core, it offers a much faster way to build applications because it looks at what is on your classpath and makes some reasonable assumptions.
33
+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.
35 34
 
36 35
 For example:
37
-- Got Spring MVC? There are a handful of needed beans people almost always use in that situation. But why stop there? A Spring MVC app 99.9% of the time needs a servlet container so Spring Boot will autoconfigure embedded Tomcat.
38
-- Got Jetty? You probably do NOT want Tomcat, but instead embedded Jetty.
39
-- Got Thymeleaf? There are a few beans that must always be added to your application context. Why should you have to track that?
40
-- 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 one into a servlet? Define one in your application context and Spring Boot will snatch it up and plug it into Spring MVC's `DispatcherServlet`.
36
+- 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.
37
+- Got Jetty? You probably do NOT want Tomcat, but instead embedded Jetty. Don't lift a finger; Spring Boot handles it for you.
38
+- 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.
39
+- 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`.
41 40
 
42
-It doesn't stop there. These are just a few examples of the automatic configuration support Spring Boot provides. But they don't get in your way. Spring Boot may make assumptions and add a `SpringTemplateEngine` for your Thymeleaf-based application. But if you proceed to define your own `SpringTemplateEngine`, Spring Boot will step aside and prefer your choice.
41
+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.
43 42
 
44 43
 Creating a simple web application
45 44
 ---------------------------------
@@ -47,18 +46,20 @@ You already have the base build file at the top. Next step is to create a web co
47 46
 
48 47
     <@snippet path="src/main/java/hello/HelloController.java" prefix="initial"/>
49 48
     
50
-The class is flagged as a `@Controller` meaing it's ready for use by Spring MVC to handle web requests. `@RequestMapping` maps `GET /` to the `index()` method. It returns pure text thanks to the `@ResponseBody` annotation.
49
+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.
51 50
 
52 51
 To make it executable, create an `Application` class:
53 52
 
54 53
     <@snippet path="src/main/java/hello/Application.java" prefix="initial"/>
55 54
     
56
-- `@Configuration` tags the class as the source for defining beans for the application context.
57
-- `@EnableAutoConfiguration` tells Spring Boot to get going and start adding beans based on classpath settings, other beans, and property settings.
58
-- `@EnableWebMvc` signals Spring MVC that this application is a web application and to activate key behaviors for that.
55
+- `@Configuration` tags the class as a source of bean definitions for the application context.
56
+- `@EnableAutoConfiguration` tells Spring Boot to get going and start adding beans based on classpath settings, other beans, and various property settings.
57
+- `@EnableWebMvc` signals Spring MVC that this application is a web application and to activate key behaviors such as setting up a `DispatcherServlet`.
59 58
 - `@ComponentScanning` tells Spring to look for other components, configurations, and services in the the `hello` package, allowing it to find the `HelloController`.
60 59
 
61
-The `main()` method uses Spring Boot's `SpringApplication.run()` method to launch an application. 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.
60
+The `main()` method uses Spring Boot's `SpringApplication.run()` method to launch an application. Did you notice that there wasn't a single line of XML? No **web.xml** file either. This web application is 100% pure Java and you didn't have to deal with configuring any plumbing or infrastructure.
61
+
62
+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.
62 63
 
63 64
 To run it, execute:
64 65
 
@@ -117,7 +118,7 @@ Greetings from Spring Boot!
117 118
 
118 119
 Switching to Jetty
119 120
 ------------------
120
-What if you preferred Jetty over Tomcat? They're both compliant choices, so it should be darn simple to switch. And it is!
121
+What if you preferred Jetty over Tomcat? They're both compliant servlet containers, so it should be darn simple to switch. And it is!
121 122
 
122 123
 Add this to your build file's list of dependencies:
123 124
 
@@ -134,7 +135,7 @@ You should also update your configuration and add a `MultipartConfigElement` to
134 135
 
135 136
     <@snippet path="src/main/java/hello/Application.java" prefix="complete"/>
136 137
     
137
-> **Note:** This `MultipartConfigElement` may not have any settings other than an empty string. A production version would specify things like target upload path, file size upload limits, etc.
138
+> **Note:** A production version of `MultipartConfigElement` would not be empty but instead specify things like target upload path, file size upload limits, etc.
138 139
 
139 140
 Re-run the app
140 141
 --------------
@@ -188,11 +189,11 @@ simpleControllerHandlerAdapter
188 189
 viewControllerHandlerMapping
189 190
 ```
190 191
 
191
-There is little change from the previous output, except there is no `tomcatEmbeddedServletContainerFactory`. Instead, there is a new `jettyEmbeddedServletContainer`. 
192
+There is little change from the previous output, except there is no longer a `tomcatEmbeddedServletContainerFactory`. Instead, there is a new `jettyEmbeddedServletContainer`. 
192 193
 
193
-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).
194
+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.
194 195
 
195
-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 aspect, the container, and adding some upload support shouldn't cause a system wide ripple.
196
+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 aspect, the container, and adding upload support shouldn't cause a system wide ripple.
196 197
 
197 198
 That is not all
198 199
 ---------------

+ 19
- 18
README.md Zobrazit soubor

@@ -2,8 +2,7 @@
2 2
 What you'll build
3 3
 -----------------
4 4
 
5
-This guide provides an introduction to Spring Boot.
6
-
5
+This guide provides an introduction to 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.
7 6
 
8 7
 What you'll need
9 8
 ----------------
@@ -114,15 +113,15 @@ In a project directory of your choosing, create the following subdirectory struc
114 113
 Warming up with Spring Boot
115 114
 ---------------------------
116 115
 
117
-What does Spring Boot provide? At the core, it offers a much faster way to build applications because it looks at what is on your classpath and makes some reasonable assumptions.
116
+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.
118 117
 
119 118
 For example:
120
-- Got Spring MVC? There are a handful of needed beans people almost always use in that situation. But why stop there? A Spring MVC app 99.9% of the time needs a servlet container so Spring Boot will autoconfigure embedded Tomcat.
121
-- Got Jetty? You probably do NOT want Tomcat, but instead embedded Jetty.
122
-- Got Thymeleaf? There are a few beans that must always be added to your application context. Why should you have to track that?
123
-- 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 one into a servlet? Define one in your application context and Spring Boot will snatch it up and plug it into Spring MVC's `DispatcherServlet`.
119
+- 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.
120
+- Got Jetty? You probably do NOT want Tomcat, but instead embedded Jetty. Don't lift a finger; Spring Boot handles it for you.
121
+- 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.
122
+- 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`.
124 123
 
125
-It doesn't stop there. These are just a few examples of the automatic configuration support Spring Boot provides. But they don't get in your way. Spring Boot may make assumptions and add a `SpringTemplateEngine` for your Thymeleaf-based application. But if you proceed to define your own `SpringTemplateEngine`, Spring Boot will step aside and prefer your choice.
124
+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.
126 125
 
127 126
 Creating a simple web application
128 127
 ---------------------------------
@@ -147,7 +146,7 @@ public class HelloController {
147 146
 }
148 147
 ```
149 148
     
150
-The class is flagged as a `@Controller` meaing it's ready for use by Spring MVC to handle web requests. `@RequestMapping` maps `GET /` to the `index()` method. It returns pure text thanks to the `@ResponseBody` annotation.
149
+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.
151 150
 
152 151
 To make it executable, create an `Application` class:
153 152
 
@@ -185,12 +184,14 @@ public class Application {
185 184
 }
186 185
 ```
187 186
     
188
-- `@Configuration` tags the class as the source for defining beans for the application context.
189
-- `@EnableAutoConfiguration` tells Spring Boot to get going and start adding beans based on classpath settings, other beans, and property settings.
190
-- `@EnableWebMvc` signals Spring MVC that this application is a web application and to activate key behaviors for that.
187
+- `@Configuration` tags the class as a source of bean definitions for the application context.
188
+- `@EnableAutoConfiguration` tells Spring Boot to get going and start adding beans based on classpath settings, other beans, and various property settings.
189
+- `@EnableWebMvc` signals Spring MVC that this application is a web application and to activate key behaviors such as setting up a `DispatcherServlet`.
191 190
 - `@ComponentScanning` tells Spring to look for other components, configurations, and services in the the `hello` package, allowing it to find the `HelloController`.
192 191
 
193
-The `main()` method uses Spring Boot's `SpringApplication.run()` method to launch an application. 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.
192
+The `main()` method uses Spring Boot's `SpringApplication.run()` method to launch an application. Did you notice that there wasn't a single line of XML? No **web.xml** file either. This web application is 100% pure Java and you didn't have to deal with configuring any plumbing or infrastructure.
193
+
194
+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.
194 195
 
195 196
 To run it, execute:
196 197
 
@@ -249,7 +250,7 @@ Greetings from Spring Boot!
249 250
 
250 251
 Switching to Jetty
251 252
 ------------------
252
-What if you preferred Jetty over Tomcat? They're both compliant choices, so it should be darn simple to switch. And it is!
253
+What if you preferred Jetty over Tomcat? They're both compliant servlet containers, so it should be darn simple to switch. And it is!
253 254
 
254 255
 Add this to your build file's list of dependencies:
255 256
 
@@ -306,7 +307,7 @@ public class Application {
306 307
 }
307 308
 ```
308 309
     
309
-> **Note:** This `MultipartConfigElement` may not have any settings other than an empty string. A production version would specify things like target upload path, file size upload limits, etc.
310
+> **Note:** A production version of `MultipartConfigElement` would not be empty but instead specify things like target upload path, file size upload limits, etc.
310 311
 
311 312
 Re-run the app
312 313
 --------------
@@ -360,11 +361,11 @@ simpleControllerHandlerAdapter
360 361
 viewControllerHandlerMapping
361 362
 ```
362 363
 
363
-There is little change from the previous output, except there is no `tomcatEmbeddedServletContainerFactory`. Instead, there is a new `jettyEmbeddedServletContainer`. 
364
+There is little change from the previous output, except there is no longer a `tomcatEmbeddedServletContainerFactory`. Instead, there is a new `jettyEmbeddedServletContainer`. 
364 365
 
365
-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).
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.
366 367
 
367
-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 aspect, the container, and adding some upload support shouldn't cause a system wide ripple.
368
+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 aspect, the container, and adding upload support shouldn't cause a system wide ripple.
368 369
 
369 370
 That is not all
370 371
 ---------------