File tree Expand file tree Collapse file tree 5 files changed +20
-30
lines changed
complete-kotlin/src/main/kotlin/com/example/testingweb
complete/src/main/java/com/example/testingweb Expand file tree Collapse file tree 5 files changed +20
-30
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ To manually initialize the project:
3434
3535. Navigate to https://start.spring.io.
3636This service pulls in all the dependencies you need for an application and does most of the setup for you.
37- . Choose either Gradle or Maven and the language you want to use: Kotlin or Java .
37+ . Choose either Gradle or Maven and the language you want to use.
3838. Click *Dependencies* and select *Spring Web*.
3939. Click *Generate*.
4040. Download the resulting ZIP file, which is an archive of a web application that is configured with your choices.
@@ -59,10 +59,6 @@ include::complete/src/main/java/com/example/testingweb/HomeController.java[]
5959include::complete-kotlin/src/main/kotlin/com/example/testingweb/HomeController.kt[]
6060----
6161
62- NOTE: The preceding example does not specify `GET` versus `PUT`, `POST`, and so forth.
63- By default `@RequestMapping` maps all HTTP operations. You can use `@GetMapping` or
64- `@RequestMapping(method=GET)` to narrow this mapping.
65-
6662
6763== Run the Application
6864
@@ -253,7 +249,7 @@ include::complete/src/test/java/com/example/testingweb/WebMockTest.java[]
253249include::complete-kotlin/src/test/kotlin/com/example/testingweb/WebMockTest.kt[]
254250----
255251
256- We use `@MockBean ` to create and inject a mock for the `GreetingService` (if you do not do
252+ We use `@MockitoBean ` to create and inject a mock for the `GreetingService` (if you do not do
257253so, the application context cannot start), and we set its expectations using `Mockito`.
258254
259255== Summary
Original file line number Diff line number Diff line change 11package com.example.testingweb
22
3- import org.springframework.stereotype.Controller
4- import org.springframework.web.bind.annotation.RequestMapping
5- import org.springframework.web.bind.annotation.ResponseBody
3+ import org.springframework.web.bind.annotation.GetMapping
4+ import org.springframework.web.bind.annotation.RestController
65
7- @Controller
6+ @RestController
87class GreetingController (private val service : GreetingService ) {
98
10- @RequestMapping(" /greeting" )
11- @ResponseBody
9+ @GetMapping(" /greeting" )
1210 fun greeting (): String = service.greet()
1311}
Original file line number Diff line number Diff line change 11package com.example.testingweb
22
3- import org.springframework.stereotype.Controller
4- import org.springframework.web.bind.annotation.RequestMapping
5- import org.springframework.web.bind.annotation.ResponseBody
3+ import org.springframework.web.bind.annotation.GetMapping
4+ import org.springframework.web.bind.annotation.RestController
65
7- @Controller
6+ @RestController
87class HomeController {
98
10- @RequestMapping(" /" )
11- @ResponseBody
9+ @GetMapping(" /" )
1210 fun greeting (): String = " Hello, World"
1311}
Original file line number Diff line number Diff line change 11package com .example .testingweb ;
22
3- import org .springframework .stereotype .Controller ;
4- import org .springframework .web .bind .annotation .RequestMapping ;
5- import org .springframework .web .bind .annotation .ResponseBody ;
3+ import org .springframework .web .bind .annotation .GetMapping ;
4+ import org .springframework .web .bind .annotation .RestController ;
65
76
8- @ Controller
7+ @ RestController
98public class GreetingController {
109
1110 private final GreetingService service ;
@@ -14,8 +13,8 @@ public GreetingController(GreetingService service) {
1413 this .service = service ;
1514 }
1615
17- @ RequestMapping ("/greeting" )
18- public @ ResponseBody String greeting () {
16+ @ GetMapping ("/greeting" )
17+ public String greeting () {
1918 return service .greet ();
2019 }
2120
Original file line number Diff line number Diff line change 11package com .example .testingweb ;
22
3- import org .springframework .stereotype .Controller ;
4- import org .springframework .web .bind .annotation .RequestMapping ;
5- import org .springframework .web .bind .annotation .ResponseBody ;
3+ import org .springframework .web .bind .annotation .GetMapping ;
4+ import org .springframework .web .bind .annotation .RestController ;
65
7- @ Controller
6+ @ RestController
87public class HomeController {
98
10- @ RequestMapping ("/" )
11- public @ ResponseBody String greeting () {
9+ @ GetMapping ("/" )
10+ public String greeting () {
1211 return "Hello, World" ;
1312 }
1413
You can’t perform that action at this time.
0 commit comments