ソースを参照

fixed conflict

Beverley Talbott 13 年 前
コミット
3b347b024b
共有1 個のファイルを変更した18 個の追加121 個の削除を含む
  1. 18
    121
      README.src.md

README.md → README.src.md ファイルの表示

@@ -24,74 +24,31 @@ What you'll need
24 24
 ----------------
25 25
 
26 26
  - About 15 minutes
27
- - {!snippet:prereq-editor-jdk-buildtools}
27
+ - {!include#prereq-editor-jdk-buildtools}
28 28
 
29
-## {!snippet:how-to-complete-this-guide}
29
+## {!include#how-to-complete-this-guide}
30 30
 
31 31
 
32 32
 <a name="scratch"></a>
33
-## Set up the project
33
+Set up the project
34
+------------------
34 35
 
36
+{!include#build-system-intro}
35 37
 
36
-{!snippet:build-system-intro}
37
-
38
-{!snippet:create-directory-structure-hello}
38
+{!include#create-directory-structure-hello}
39 39
 
40 40
 ### Create a Maven POM
41 41
 
42
-{!snippet:maven-project-setup-options}
43
-
44
-`pom.xml`
45
-```xml
46
-<?xml version="1.0" encoding="UTF-8"?>
47
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
48
-    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
49
-    <modelVersion>4.0.0</modelVersion>
50
-
51
-    <groupId>org.springframework</groupId>
52
-    <artifactId>gs-rest-service</artifactId>
53
-    <version>0.1.0</version>
54
-
55
-    <parent>
56
-        <groupId>org.springframework.bootstrap</groupId>
57
-        <artifactId>spring-bootstrap-starters</artifactId>
58
-        <version>0.5.0.BUILD-SNAPSHOT</version>
59
-    </parent>
60
-
61
-    <dependencies>
62
-        <dependency>
63
-            <groupId>org.springframework.bootstrap</groupId>
64
-            <artifactId>spring-bootstrap-web-starter</artifactId>
65
-        </dependency>
66
-        <dependency>
67
-            <groupId>com.fasterxml.jackson.core</groupId>
68
-            <artifactId>jackson-databind</artifactId>
69
-        </dependency>
70
-    </dependencies>
71
-
72
-    <!-- TODO: remove once bootstrap goes GA -->
73
-    <repositories>
74
-        <repository>
75
-            <id>spring-snapshots</id>
76
-            <url>http://repo.springsource.org/snapshot</url>
77
-            <snapshots><enabled>true</enabled></snapshots>
78
-        </repository>
79
-    </repositories>
80
-    <pluginRepositories>
81
-        <pluginRepository>
82
-            <id>spring-snapshots</id>
83
-            <url>http://repo.springsource.org/snapshot</url>
84
-            <snapshots><enabled>true</enabled></snapshots>
85
-        </pluginRepository>
86
-    </pluginRepositories>
87
-</project>
88
-```
89
-
90
-{!snippet:bootstrap-starter-pom-disclaimer}
42
+{!include#maven-project-setup-options}
43
+
44
+    {!include:initial/pom.xml}
45
+
46
+{!include#bootstrap-starter-pom-disclaimer}
91 47
 
92 48
 
93 49
 <a name="initial"></a>
94
-## Create a resource representation class
50
+Create a resource representation class
51
+--------------------------------------
95 52
 
96 53
 Now that you've set up the project and build system, you can create your web service.
97 54
 
@@ -108,29 +65,7 @@ The `id` field is a unique identifier for the greeting, and `content` is the tex
108 65
 
109 66
 To model the greeting representation, you create a _resource representation class_. To do this, you simply create a plain old java object with fields, constructors, and accessors for the `id` and `content` data:
110 67
 
111
-`src/main/java/hello/Greeting.java`
112
-```java
113
-package hello;
114
-
115
-public class Greeting {
116
-
117
-    private final long id;
118
-    private final String content;
119
-
120
-    public Greeting(long id, String content) {
121
-        this.id = id;
122
-        this.content = content;
123
-    }
124
-
125
-    public long getId() {
126
-        return id;
127
-    }
128
-
129
-    public String getContent() {
130
-        return content;
131
-    }
132
-}
133
-```
68
+    {!include:complete/src/main/java/hello/Greeting.java}
134 69
 
135 70
 > **Note:** As you'll see in steps below, Spring will use the _Jackson_ JSON library to automatically marshal instances of type `Greeting` into JSON.
136 71
 
@@ -142,30 +77,7 @@ Create a resource controller
142 77
 
143 78
 In Spring's approach to building RESTful web services, HTTP requests are handled by a _controller_. These components are easily identified by the [`@Controller`][] annotation, and the `GreetingController` below handles `GET` requests for `/greeting` by returning a new instance of the `Greeting` class:
144 79
 
145
-`src/main/java/hello/GreetingController.java`
146
-```java
147
-package hello;
148
-
149
-import java.util.concurrent.atomic.AtomicLong;
150
-import org.springframework.stereotype.Controller;
151
-import org.springframework.web.bind.annotation.RequestMapping;
152
-import org.springframework.web.bind.annotation.RequestParam;
153
-import org.springframework.web.bind.annotation.ResponseBody;
154
-
155
-@Controller
156
-public class GreetingController {
157
-
158
-    private static final String template = "Hello, %s!";
159
-    private final AtomicLong counter = new AtomicLong();
160
-
161
-    @RequestMapping("/greeting")
162
-    public @ResponseBody Greeting greeting(
163
-            @RequestParam(value="name", required=false, defaultValue="World") String name) {
164
-        return new Greeting(counter.incrementAndGet(),
165
-                            String.format(template, name));
166
-    }
167
-}
168
-```
80
+    {!include:complete/src/main/java/hello/GreetingController.java}
169 81
 
170 82
 This controller is concise and simple, but there's plenty going on under the hood. Let's break it down step by step.
171 83
 
@@ -190,31 +102,16 @@ Make the application executable
190 102
 Although it is possible to package this service as a traditional _web application archive_ or [WAR][u-war] file for deployment to an external application server, the simpler approach demonstrated below creates a _standalone application_. You package everything in a single, executable JAR file, driven by a good old Java `main()` method. And along the way, you use Spring's support for embedding the [Tomcat][u-tomcat] servlet container as the HTTP runtime, instead of deploying to an external instance.
191 103
 
192 104
 ### Create a main class
193
-The `main()` method defers to the [`SpringApplication`][] helper class, providing `Application.class` as an argument to its `run()` method. This tells Spring to read the annotation metadata from `Application` and to manage it as a component in the _[Spring application context][u-application-context]_.
194
-
195
-`src/main/java/hello/Application.java`
196
-
197
-```java
198
-package hello;
199 105
 
200
-import org.springframework.bootstrap.SpringApplication;
201
-import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
202
-import org.springframework.context.annotation.ComponentScan;
106
+    {!include:complete/src/main/java/hello/Application.java}
203 107
 
204
-@ComponentScan
205
-@EnableAutoConfiguration
206
-public class Application {
108
+The `main()` method defers to the [`SpringApplication`][] helper class, providing `Application.class` as an argument to its `run()` method. This tells Spring to read the annotation metadata from `Application` and to manage it as a component in the _[Spring application context][u-application-context]_.
207 109
 
208
-    public static void main(String[] args) {
209
-        SpringApplication.run(Application.class, args);
210
-    }
211
-}
212
-```
213 110
 The `@ComponentScan` annotation tells Spring to search recursively through the `hello` package and its children for classes marked directly or indirectly with Spring's [`@Component`][] annotation. This directive ensures that Spring finds and registers the `GreetingController`, because it is marked with `@Controller`, which in turn is a kind of `@Component` annotation.
214 111
 
215 112
 The [`@EnableAutoConfiguration`][] annotation switches on reasonable default behaviors based on the content of your classpath. For example, because the application depends on the embeddable version of Tomcat (tomcat-embed-core.jar), a Tomcat server is set up and configured with reasonable defaults on your behalf. And because the application also depends on Spring MVC (spring-webmvc.jar), a Spring MVC [`DispatcherServlet`][] is configured and registered for you — no `web.xml` necessary! Auto-configuration is a powerful, flexible mechanism. See the [API documentation][`@EnableAutoConfiguration`] for further details.
216 113
 
217
-### {!snippet:build-an-executable-jar}
114
+### {!include#build-an-executable-jar}
218 115
 
219 116
 
220 117
 Run the service