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

Write draft of getting started guide with before/after demo

Greg Turnquist 13 лет назад
Родитель
Сommit
51a6ece694

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

@@ -0,0 +1,228 @@
1
+<#assign project_id="gs-spring-boot">
2
+
3
+What you'll build
4
+-----------------
5
+
6
+This guide provides an introduction to Spring Boot.
7
+
8
+
9
+What you'll need
10
+----------------
11
+
12
+ - About 15 minutes
13
+ - <@prereq_editor_jdk_buildtools/>
14
+
15
+
16
+## <@how_to_complete_this_guide jump_ahead="Warming up with Spring Boot"/>
17
+
18
+
19
+<a name="scratch"></a>
20
+Set up the project
21
+------------------
22
+
23
+<@build_system_intro/>
24
+
25
+<@create_directory_structure_hello/>
26
+
27
+### Create a Maven POM
28
+
29
+    <@snippet path="pom.xml" prefix="initial"/>
30
+
31
+Warming up with Spring Boot
32
+---------------------------
33
+
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.
35
+
36
+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`.
41
+
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.
43
+
44
+Creating a simple web application
45
+---------------------------------
46
+You already have the base build file at the top. Next step is to create a web controller for a simple web application.
47
+
48
+    <@snippet path="src/main/java/hello/HelloController.java" prefix="initial"/>
49
+    
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.
51
+
52
+To make it executable, create an `Application` class:
53
+
54
+    <@snippet path="src/main/java/hello/Application.java" prefix="initial"/>
55
+    
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.
59
+- `@ComponentScanning` tells Spring to look for other components, configurations, and services in the the `hello` package, allowing it to find the `HelloController`.
60
+
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.
62
+
63
+To run it, execute:
64
+
65
+```sh
66
+$ mvn package spring-boot:run
67
+```
68
+
69
+You should see some output like this:
70
+
71
+```txt
72
+Let's inspect the beans provided by Spring Boot:
73
+application
74
+beanNameHandlerMapping
75
+defaultServletHandlerMapping
76
+dispatcherServlet
77
+embeddedServletContainerCustomizerBeanPostProcessor
78
+handlerExceptionResolver
79
+helloController
80
+httpRequestHandlerAdapter
81
+messageSource
82
+mvcContentNegotiationManager
83
+mvcConversionService
84
+mvcValidator
85
+org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration
86
+org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
87
+org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration
88
+org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$DispatcherServletConfiguration
89
+org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat
90
+org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
91
+org.springframework.boot.context.embedded.properties.ServerProperties
92
+org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor
93
+org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor
94
+org.springframework.context.annotation.internalAutowiredAnnotationProcessor
95
+org.springframework.context.annotation.internalCommonAnnotationProcessor
96
+org.springframework.context.annotation.internalConfigurationAnnotationProcessor
97
+org.springframework.context.annotation.internalRequiredAnnotationProcessor
98
+org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration
99
+propertySourcesBinder
100
+propertySourcesPlaceholderConfigurer
101
+requestMappingHandlerAdapter
102
+requestMappingHandlerMapping
103
+resourceHandlerMapping
104
+simpleControllerHandlerAdapter
105
+tomcatEmbeddedServletContainerFactory
106
+viewControllerHandlerMapping
107
+```
108
+
109
+You can clearly see **org.springframework.boot.autoconfigure** beans. There is also a `tomcatEmbeddedServletContainerFactory`.
110
+
111
+Check out the service.
112
+
113
+```sh
114
+$ curl localhost:8080
115
+Greetings from Spring Boot!
116
+```
117
+
118
+Switching to Jetty
119
+------------------
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
+
122
+Add this to your build file's list of dependencies:
123
+
124
+```xml
125
+        <dependency>
126
+            <groupId>org.springframework.boot</groupId>
127
+            <artifactId>spring-boot-up-jetty</artifactId>
128
+        </dependency>
129
+```
130
+
131
+Adding multipart upload support
132
+-------------------------------
133
+You should also update your configuration and add a `MultipartConfigElement` to the application context.
134
+
135
+    <@snippet path="src/main/java/hello/Application.java" prefix="complete"/>
136
+    
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
+
139
+Re-run the app
140
+--------------
141
+
142
+Run the app again:
143
+
144
+```sh
145
+$ mvn package spring-boot:run
146
+```
147
+
148
+Now check out the output:
149
+
150
+```txt
151
+Let's inspect the beans provided by Spring Boot:
152
+application
153
+beanNameHandlerMapping
154
+defaultServletHandlerMapping
155
+dispatcherServlet
156
+embeddedServletContainerCustomizerBeanPostProcessor
157
+handlerExceptionResolver
158
+helloController
159
+httpRequestHandlerAdapter
160
+jettyEmbeddedServletContainerFactory
161
+messageSource
162
+multipartConfigElement
163
+multipartResolver
164
+mvcContentNegotiationManager
165
+mvcConversionService
166
+mvcValidator
167
+org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration
168
+org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
169
+org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration
170
+org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$DispatcherServletConfiguration
171
+org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$EmbeddedJetty
172
+org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration
173
+org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
174
+org.springframework.boot.context.embedded.properties.ServerProperties
175
+org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor
176
+org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor
177
+org.springframework.context.annotation.internalAutowiredAnnotationProcessor
178
+org.springframework.context.annotation.internalCommonAnnotationProcessor
179
+org.springframework.context.annotation.internalConfigurationAnnotationProcessor
180
+org.springframework.context.annotation.internalRequiredAnnotationProcessor
181
+org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration
182
+propertySourcesBinder
183
+propertySourcesPlaceholderConfigurer
184
+requestMappingHandlerAdapter
185
+requestMappingHandlerMapping
186
+resourceHandlerMapping
187
+simpleControllerHandlerAdapter
188
+viewControllerHandlerMapping
189
+```
190
+
191
+There is little change from the previous output, except there is no `tomcatEmbeddedServletContainerFactory`. Instead, there is a new `jettyEmbeddedServletContainer`. 
192
+
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
+
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
+
197
+That is not all
198
+---------------
199
+That last example showed how Spring Boot makes it easy to wire beans you may not be aware you need. But Spring Boot does more than that. 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`.
200
+
201
+Spring Boot provides more than a quick way to wire beans. Spring Boot's [actuator module](https://github.com/SpringSource/spring-boot/blob/master/spring-boot-actuator/README.md) adds common needed business components like health, metrics, audits, and other features.
202
+
203
+Spring Boot also have Groovy support, allowing you to dynamically build web apps like this:
204
+```groovy
205
+@Controller
206
+class ThisWillActuallyRun {
207
+
208
+    @RequestMapping("/")
209
+    @ResponseBody
210
+    String home() {
211
+        return "Hello World!"
212
+    }
213
+
214
+}
215
+```
216
+Spring Boot automatically laces the code with key annotations and Groovy Grapes to pull down needed libraries to make the app run. With Spring Boot's CLI tool, all you need do is:
217
+
218
+```txt
219
+$ spring run app.groovy
220
+$ curl localhost:8080
221
+Hello World!
222
+```
223
+
224
+Congratulations!
225
+----------------
226
+Spring Boot is powerful, but frankly too big to fit into a single guide. This is just a sampling.
227
+
228
+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.

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

@@ -0,0 +1,400 @@
1
+
2
+What you'll build
3
+-----------------
4
+
5
+This guide provides an introduction to Spring Boot.
6
+
7
+
8
+What you'll need
9
+----------------
10
+
11
+ - About 15 minutes
12
+ - A favorite text editor or IDE
13
+ - [JDK 6][jdk] or later
14
+ - [Maven 3.0][mvn] or later
15
+
16
+[jdk]: http://www.oracle.com/technetwork/java/javase/downloads/index.html
17
+[mvn]: http://maven.apache.org/download.cgi
18
+
19
+
20
+How to complete this guide
21
+--------------------------
22
+
23
+Like all Spring's [Getting Started guides](/guides/gs), you can start from scratch and complete each step, or you can bypass basic setup steps that are already familiar to you. Either way, you end up with working code.
24
+
25
+To **start from scratch**, move on to [Set up the project](#scratch).
26
+
27
+To **skip the basics**, do the following:
28
+
29
+ - [Download][zip] and unzip the source repository for this guide, or clone it using [git](/understanding/git):
30
+`git clone https://github.com/springframework-meta/gs-spring-boot.git`
31
+ - cd into `gs-spring-boot/initial`.
32
+ - Jump ahead to [Warming up with Spring Boot](#initial).
33
+
34
+**When you're finished**, you can check your results against the code in `gs-spring-boot/complete`.
35
+[zip]: https://github.com/springframework-meta/gs-spring-boot/archive/master.zip
36
+
37
+
38
+<a name="scratch"></a>
39
+Set up the project
40
+------------------
41
+
42
+First you set up a basic build script. You can use any build system you like when building apps with Spring, but the code you need to work with [Maven](https://maven.apache.org) and [Gradle](http://gradle.org) is included here. If you're not familiar with either, refer to [Building Java Projects with Maven](/guides/gs/maven/content) or [Building Java Projects with Gradle](/guides/gs/gradle/content).
43
+
44
+### Create the directory structure
45
+
46
+In a project directory of your choosing, create the following subdirectory structure; for example, with `mkdir -p src/main/java/hello` on *nix systems:
47
+
48
+    └── src
49
+        └── main
50
+            └── java
51
+                └── hello
52
+
53
+### Create a Maven POM
54
+
55
+`pom.xml`
56
+```xml
57
+<?xml version="1.0" encoding="UTF-8"?>
58
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
59
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
60
+    <modelVersion>4.0.0</modelVersion>
61
+
62
+    <groupId>org.springframework</groupId>
63
+    <artifactId>gs-spring-boot-initial</artifactId>
64
+    <version>0.1.0</version>
65
+
66
+    <parent>
67
+        <groupId>org.springframework.boot</groupId>
68
+        <artifactId>spring-boot-up-parent</artifactId>
69
+        <version>0.5.0.BUILD-SNAPSHOT</version>
70
+    </parent>
71
+
72
+    <dependencies>
73
+        <dependency>
74
+            <groupId>org.springframework.boot</groupId>
75
+            <artifactId>spring-boot-up-web</artifactId>
76
+        </dependency>
77
+        <dependency>
78
+            <groupId>com.fasterxml.jackson.core</groupId>
79
+            <artifactId>jackson-databind</artifactId>
80
+        </dependency>
81
+    </dependencies>
82
+
83
+    <properties>
84
+        <start-class>hello.Application</start-class>
85
+    </properties>
86
+
87
+    <build>
88
+        <plugins>
89
+            <plugin>
90
+                <groupId>org.springframework.boot</groupId>
91
+                <artifactId>spring-boot-maven-plugin</artifactId>
92
+            </plugin>
93
+        </plugins>
94
+    </build>
95
+
96
+    <!-- TODO: remove once bootstrap goes GA -->
97
+    <repositories>
98
+        <repository>
99
+            <id>spring-snapshots</id>
100
+            <url>http://repo.springsource.org/snapshot</url>
101
+            <snapshots><enabled>true</enabled></snapshots>
102
+        </repository>
103
+    </repositories>
104
+    <pluginRepositories>
105
+        <pluginRepository>
106
+            <id>spring-snapshots</id>
107
+            <url>http://repo.springsource.org/snapshot</url>
108
+            <snapshots><enabled>true</enabled></snapshots>
109
+        </pluginRepository>
110
+    </pluginRepositories>
111
+</project>
112
+```
113
+
114
+Warming up with Spring Boot
115
+---------------------------
116
+
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.
118
+
119
+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`.
124
+
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.
126
+
127
+Creating a simple web application
128
+---------------------------------
129
+You already have the base build file at the top. Next step is to create a web controller for a simple web application.
130
+
131
+`src/main/java/hello/HelloController.java`
132
+```java
133
+package hello;
134
+
135
+import org.springframework.stereotype.Controller;
136
+import org.springframework.web.bind.annotation.RequestMapping;
137
+import org.springframework.web.bind.annotation.ResponseBody;
138
+
139
+@Controller
140
+public class HelloController {
141
+	
142
+	@RequestMapping("/")
143
+	public @ResponseBody String index() {
144
+		return "Greetings from Spring Boot!";
145
+	}
146
+	
147
+}
148
+```
149
+    
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.
151
+
152
+To make it executable, create an `Application` class:
153
+
154
+`src/main/java/hello/Application.java`
155
+```java
156
+package hello;
157
+
158
+import java.util.Arrays;
159
+
160
+import org.springframework.boot.SpringApplication;
161
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
162
+import org.springframework.context.ApplicationContext;
163
+import org.springframework.context.annotation.ComponentScan;
164
+import org.springframework.context.annotation.Configuration;
165
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
166
+
167
+@Configuration
168
+@EnableAutoConfiguration
169
+@EnableWebMvc
170
+@ComponentScan
171
+public class Application {
172
+	
173
+	public static void main(String[] args) {
174
+		ApplicationContext ctx = SpringApplication.run(Application.class, args);
175
+		
176
+		System.out.println("Let's inspect the beans provided by Spring Boot:");
177
+		
178
+		String[] beanNames = ctx.getBeanDefinitionNames();
179
+		Arrays.sort(beanNames);
180
+		for (String beanName : beanNames) {
181
+			System.out.println(beanName);
182
+		}
183
+	}
184
+
185
+}
186
+```
187
+    
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.
191
+- `@ComponentScanning` tells Spring to look for other components, configurations, and services in the the `hello` package, allowing it to find the `HelloController`.
192
+
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.
194
+
195
+To run it, execute:
196
+
197
+```sh
198
+$ mvn package spring-boot:run
199
+```
200
+
201
+You should see some output like this:
202
+
203
+```txt
204
+Let's inspect the beans provided by Spring Boot:
205
+application
206
+beanNameHandlerMapping
207
+defaultServletHandlerMapping
208
+dispatcherServlet
209
+embeddedServletContainerCustomizerBeanPostProcessor
210
+handlerExceptionResolver
211
+helloController
212
+httpRequestHandlerAdapter
213
+messageSource
214
+mvcContentNegotiationManager
215
+mvcConversionService
216
+mvcValidator
217
+org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration
218
+org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
219
+org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration
220
+org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$DispatcherServletConfiguration
221
+org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$EmbeddedTomcat
222
+org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
223
+org.springframework.boot.context.embedded.properties.ServerProperties
224
+org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor
225
+org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor
226
+org.springframework.context.annotation.internalAutowiredAnnotationProcessor
227
+org.springframework.context.annotation.internalCommonAnnotationProcessor
228
+org.springframework.context.annotation.internalConfigurationAnnotationProcessor
229
+org.springframework.context.annotation.internalRequiredAnnotationProcessor
230
+org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration
231
+propertySourcesBinder
232
+propertySourcesPlaceholderConfigurer
233
+requestMappingHandlerAdapter
234
+requestMappingHandlerMapping
235
+resourceHandlerMapping
236
+simpleControllerHandlerAdapter
237
+tomcatEmbeddedServletContainerFactory
238
+viewControllerHandlerMapping
239
+```
240
+
241
+You can clearly see **org.springframework.boot.autoconfigure** beans. There is also a `tomcatEmbeddedServletContainerFactory`.
242
+
243
+Check out the service.
244
+
245
+```sh
246
+$ curl localhost:8080
247
+Greetings from Spring Boot!
248
+```
249
+
250
+Switching to Jetty
251
+------------------
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
+
254
+Add this to your build file's list of dependencies:
255
+
256
+```xml
257
+        <dependency>
258
+            <groupId>org.springframework.boot</groupId>
259
+            <artifactId>spring-boot-up-jetty</artifactId>
260
+        </dependency>
261
+```
262
+
263
+Adding multipart upload support
264
+-------------------------------
265
+You should also update your configuration and add a `MultipartConfigElement` to the application context.
266
+
267
+`src/main/java/hello/Application.java`
268
+```java
269
+package hello;
270
+
271
+import java.util.Arrays;
272
+
273
+import javax.servlet.MultipartConfigElement;
274
+
275
+import org.springframework.boot.SpringApplication;
276
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
277
+import org.springframework.context.ApplicationContext;
278
+import org.springframework.context.annotation.Bean;
279
+import org.springframework.context.annotation.ComponentScan;
280
+import org.springframework.context.annotation.Configuration;
281
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
282
+
283
+@Configuration
284
+@EnableAutoConfiguration
285
+@EnableWebMvc
286
+@ComponentScan
287
+public class Application {
288
+	
289
+	@Bean
290
+	MultipartConfigElement multipartConfigElement() {
291
+		return new MultipartConfigElement("");
292
+	}
293
+	
294
+	public static void main(String[] args) {
295
+		ApplicationContext ctx = SpringApplication.run(Application.class, args);
296
+		
297
+		System.out.println("Let's inspect the beans provided by Spring Boot:");
298
+		
299
+		String[] beanNames = ctx.getBeanDefinitionNames();
300
+		Arrays.sort(beanNames);
301
+		for (String beanName : beanNames) {
302
+			System.out.println(beanName);
303
+		}
304
+	}
305
+
306
+}
307
+```
308
+    
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
+
311
+Re-run the app
312
+--------------
313
+
314
+Run the app again:
315
+
316
+```sh
317
+$ mvn package spring-boot:run
318
+```
319
+
320
+Now check out the output:
321
+
322
+```txt
323
+Let's inspect the beans provided by Spring Boot:
324
+application
325
+beanNameHandlerMapping
326
+defaultServletHandlerMapping
327
+dispatcherServlet
328
+embeddedServletContainerCustomizerBeanPostProcessor
329
+handlerExceptionResolver
330
+helloController
331
+httpRequestHandlerAdapter
332
+jettyEmbeddedServletContainerFactory
333
+messageSource
334
+multipartConfigElement
335
+multipartResolver
336
+mvcContentNegotiationManager
337
+mvcConversionService
338
+mvcValidator
339
+org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration
340
+org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
341
+org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration
342
+org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$DispatcherServletConfiguration
343
+org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$EmbeddedJetty
344
+org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration
345
+org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
346
+org.springframework.boot.context.embedded.properties.ServerProperties
347
+org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor
348
+org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor
349
+org.springframework.context.annotation.internalAutowiredAnnotationProcessor
350
+org.springframework.context.annotation.internalCommonAnnotationProcessor
351
+org.springframework.context.annotation.internalConfigurationAnnotationProcessor
352
+org.springframework.context.annotation.internalRequiredAnnotationProcessor
353
+org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration
354
+propertySourcesBinder
355
+propertySourcesPlaceholderConfigurer
356
+requestMappingHandlerAdapter
357
+requestMappingHandlerMapping
358
+resourceHandlerMapping
359
+simpleControllerHandlerAdapter
360
+viewControllerHandlerMapping
361
+```
362
+
363
+There is little change from the previous output, except there is no `tomcatEmbeddedServletContainerFactory`. Instead, there is a new `jettyEmbeddedServletContainer`. 
364
+
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
+
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
+
369
+That is not all
370
+---------------
371
+That last example showed how Spring Boot makes it easy to wire beans you may not be aware you need. But Spring Boot does more than that. 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`.
372
+
373
+Spring Boot provides more than a quick way to wire beans. Spring Boot's [actuator module](https://github.com/SpringSource/spring-boot/blob/master/spring-boot-actuator/README.md) adds common needed business components like health, metrics, audits, and other features.
374
+
375
+Spring Boot also have Groovy support, allowing you to dynamically build web apps like this:
376
+```groovy
377
+@Controller
378
+class ThisWillActuallyRun {
379
+
380
+    @RequestMapping("/")
381
+    @ResponseBody
382
+    String home() {
383
+        return "Hello World!"
384
+    }
385
+
386
+}
387
+```
388
+Spring Boot automatically laces the code with key annotations and Groovy Grapes to pull down needed libraries to make the app run. With Spring Boot's CLI tool, all you need do is:
389
+
390
+```txt
391
+$ spring run app.groovy
392
+$ curl localhost:8080
393
+Hello World!
394
+```
395
+
396
+Congratulations!
397
+----------------
398
+Spring Boot is powerful, but frankly too big to fit into a single guide. This is just a sampling.
399
+
400
+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.

+ 4
- 0
complete/pom.xml Просмотреть файл

@@ -19,6 +19,10 @@
19 19
             <artifactId>spring-boot-up-web</artifactId>
20 20
         </dependency>
21 21
         <dependency>
22
+            <groupId>org.springframework.boot</groupId>
23
+            <artifactId>spring-boot-up-jetty</artifactId>
24
+        </dependency>
25
+        <dependency>
22 26
             <groupId>com.fasterxml.jackson.core</groupId>
23 27
             <artifactId>jackson-databind</artifactId>
24 28
         </dependency>

+ 20
- 1
complete/src/main/java/hello/Application.java Просмотреть файл

@@ -1,7 +1,13 @@
1 1
 package hello;
2 2
 
3
+import java.util.Arrays;
4
+
5
+import javax.servlet.MultipartConfigElement;
6
+
3 7
 import org.springframework.boot.SpringApplication;
4 8
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
9
+import org.springframework.context.ApplicationContext;
10
+import org.springframework.context.annotation.Bean;
5 11
 import org.springframework.context.annotation.ComponentScan;
6 12
 import org.springframework.context.annotation.Configuration;
7 13
 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@@ -12,8 +18,21 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
12 18
 @ComponentScan
13 19
 public class Application {
14 20
 	
21
+	@Bean
22
+	MultipartConfigElement multipartConfigElement() {
23
+		return new MultipartConfigElement("");
24
+	}
25
+	
15 26
 	public static void main(String[] args) {
16
-		SpringApplication.run(Application.class, args);
27
+		ApplicationContext ctx = SpringApplication.run(Application.class, args);
28
+		
29
+		System.out.println("Let's inspect the beans provided by Spring Boot:");
30
+		
31
+		String[] beanNames = ctx.getBeanDefinitionNames();
32
+		Arrays.sort(beanNames);
33
+		for (String beanName : beanNames) {
34
+			System.out.println(beanName);
35
+		}
17 36
 	}
18 37
 
19 38
 }

+ 1
- 1
complete/src/main/java/hello/HelloController.java Просмотреть файл

@@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
6 6
 
7 7
 @Controller
8 8
 public class HelloController {
9
-
9
+	
10 10
 	@RequestMapping("/")
11 11
 	public @ResponseBody String index() {
12 12
 		return "Greetings from Spring Boot!";

+ 13
- 0
initial/pom.xml Просмотреть файл

@@ -24,6 +24,19 @@
24 24
         </dependency>
25 25
     </dependencies>
26 26
 
27
+    <properties>
28
+        <start-class>hello.Application</start-class>
29
+    </properties>
30
+
31
+    <build>
32
+        <plugins>
33
+            <plugin>
34
+                <groupId>org.springframework.boot</groupId>
35
+                <artifactId>spring-boot-maven-plugin</artifactId>
36
+            </plugin>
37
+        </plugins>
38
+    </build>
39
+
27 40
     <!-- TODO: remove once bootstrap goes GA -->
28 41
     <repositories>
29 42
         <repository>

+ 0
- 0
initial/src/main/java/hello/.gitignore Просмотреть файл


+ 30
- 0
initial/src/main/java/hello/Application.java Просмотреть файл

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

+ 15
- 0
initial/src/main/java/hello/HelloController.java Просмотреть файл

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