|
|
@@ -144,9 +144,9 @@ public class Greeting {
|
|
144
|
144
|
}
|
|
145
|
145
|
```
|
|
146
|
146
|
|
|
147
|
|
-As you'll see, Spring uses _Jackson_ library to automatically marshal instances of type `Greeting` into JSON.
|
|
|
147
|
+> **Note:** As you'll see in steps below, Spring will use the _Jackson_ JSON library to automatically marshal instances of type `Greeting` into JSON.
|
|
148
|
148
|
|
|
149
|
|
-Next you create the resource controller that will serve the resource representation class.
|
|
|
149
|
+Next you create the resource controller that will serve these greetings.
|
|
150
|
150
|
|
|
151
|
151
|
|
|
152
|
152
|
Create a resource controller
|
|
|
@@ -189,9 +189,9 @@ The `@RequestMapping` annotation ensures that HTTP requests to `/greeting` are m
|
|
189
|
189
|
|
|
190
|
190
|
The implementation of the method body creates and returns a new `Greeting` object with `id` and `content` attributes based on the next value from the `counter`, and formats the given `name` by using the greeting `template`.
|
|
191
|
191
|
|
|
192
|
|
-A key difference between a traditional MVC controller and the RESTful web service controller above is the way that the HTTP response body is created. Rather than relying on a view technology (such as [JSP][u-jsp]) to perform server-side rendering of the greeting data to HTML, this RESTful web service controller simply populates and returns a `Greeting` object. The object data is written directly to the HTTP response as JSON.
|
|
|
192
|
+A key difference between a traditional MVC controller and the RESTful web service controller above is the way that the HTTP response body is created. Rather than relying on a view technology (such as [JSP][u-jsp]) to perform server-side rendering of the greeting data to HTML, this RESTful web service controller simply populates and returns a `Greeting` object. The object data will be written directly to the HTTP response as JSON.
|
|
193
|
193
|
|
|
194
|
|
-To accmplish this, the [`@ResponseBody`][] annotation on the `greeting()` method tells Spring MVC that it does not need to render the greeting object through a server-side view layer, but that instead that the greeting object returned _is_ the response body, and should be written out directly.
|
|
|
194
|
+To accomplish this, the [`@ResponseBody`][] annotation on the `greeting()` method tells Spring MVC that it does not need to render the greeting object through a server-side view layer, but that instead that the greeting object returned _is_ the response body, and should be written out directly.
|
|
195
|
195
|
|
|
196
|
196
|
The `Greeting` object must be converted to JSON. Thanks to Spring's _HTTP message converter_ support, you don't need to do this conversion manually. Because [Jackson 2][jackson] is on the classpath, Spring's [`MappingJackson2HttpMessageConverter`][] is automatically chosen to convert the `Greeting` instance to JSON.
|
|
197
|
197
|
|
|
|
@@ -199,7 +199,7 @@ The `Greeting` object must be converted to JSON. Thanks to Spring's _HTTP messag
|
|
199
|
199
|
Make the application executable
|
|
200
|
200
|
-------------------------------
|
|
201
|
201
|
|
|
202
|
|
-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 support for embedding the [Tomcat][u-tomcat] servlet container as the HTTP runtime, instead of deploying to an external instance.
|
|
|
202
|
+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.
|
|
203
|
203
|
|
|
204
|
204
|
### Create a main class
|
|
205
|
205
|
|
|
|
@@ -287,7 +287,7 @@ Notice also how the `id` attribute has changed from `1` to `2`. This proves that
|
|
287
|
287
|
Summary
|
|
288
|
288
|
-------
|
|
289
|
289
|
|
|
290
|
|
-Congrats! You've just developed a RESTful web service with Spring. This of course is just the beginning, and there are many more features to explore and implement. Be sure to check out Spring's support for [securing](TODO), [testing](TODO), [describing](TODO) and [managing](TODO) RESTful web services.
|
|
|
290
|
+Congrats! You've just developed a RESTful web service with Spring. This of course is just the beginning, and there are many more features to explore and take advantage of. Be sure to check out Spring's support for [securing](TODO), [testing](TODO), [describing](TODO) and [managing](TODO) RESTful web services.
|
|
291
|
291
|
|
|
292
|
292
|
|
|
293
|
293
|
[mvn]: http://maven.apache.org/download.cgi
|