Skip to content

Commit 3348ed5

Browse files
committed
Make use of new GetMapping and PostMapping annotations
Closes spring-projectsgh-5277
1 parent 12bd537 commit 3348ed5

File tree

49 files changed

+144
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+144
-140
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EndpointMvcAdapter.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
import org.springframework.boot.actuate.endpoint.Endpoint;
2020
import org.springframework.http.MediaType;
21-
import org.springframework.web.bind.annotation.RequestMapping;
22-
import org.springframework.web.bind.annotation.RequestMethod;
21+
import org.springframework.web.bind.annotation.GetMapping;
2322
import org.springframework.web.bind.annotation.ResponseBody;
2423

2524
/**
@@ -39,7 +38,7 @@ public EndpointMvcAdapter(Endpoint<?> delegate) {
3938
}
4039

4140
@Override
42-
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
41+
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
4342
@ResponseBody
4443
public Object invoke() {
4544
return super.invoke();

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/EnvironmentMvcEndpoint.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
import org.springframework.core.env.PropertySources;
2727
import org.springframework.http.HttpStatus;
2828
import org.springframework.http.MediaType;
29+
import org.springframework.web.bind.annotation.GetMapping;
2930
import org.springframework.web.bind.annotation.PathVariable;
30-
import org.springframework.web.bind.annotation.RequestMapping;
31-
import org.springframework.web.bind.annotation.RequestMethod;
3231
import org.springframework.web.bind.annotation.ResponseBody;
3332
import org.springframework.web.bind.annotation.ResponseStatus;
3433

@@ -49,7 +48,7 @@ public EnvironmentMvcEndpoint(EnvironmentEndpoint delegate) {
4948
super(delegate);
5049
}
5150

52-
@RequestMapping(value = "/{name:.*}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
51+
@GetMapping(value = "/{name:.*}", produces = MediaType.APPLICATION_JSON_VALUE)
5352
@ResponseBody
5453
@HypermediaDisabled
5554
public Object value(@PathVariable String name) {

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/MetricsMvcEndpoint.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
import org.springframework.boot.context.properties.ConfigurationProperties;
2323
import org.springframework.http.HttpStatus;
2424
import org.springframework.http.MediaType;
25+
import org.springframework.web.bind.annotation.GetMapping;
2526
import org.springframework.web.bind.annotation.PathVariable;
26-
import org.springframework.web.bind.annotation.RequestMapping;
27-
import org.springframework.web.bind.annotation.RequestMethod;
2827
import org.springframework.web.bind.annotation.ResponseBody;
2928
import org.springframework.web.bind.annotation.ResponseStatus;
3029

@@ -45,7 +44,7 @@ public MetricsMvcEndpoint(MetricsEndpoint delegate) {
4544
this.delegate = delegate;
4645
}
4746

48-
@RequestMapping(value = "/{name:.*}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
47+
@GetMapping(value = "/{name:.*}", produces = MediaType.APPLICATION_JSON_VALUE)
4948
@ResponseBody
5049
@HypermediaDisabled
5150
public Object value(@PathVariable String name) {

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/ShutdownMvcEndpoint.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
import org.springframework.boot.context.properties.ConfigurationProperties;
2424
import org.springframework.http.HttpStatus;
2525
import org.springframework.http.ResponseEntity;
26-
import org.springframework.web.bind.annotation.RequestMapping;
27-
import org.springframework.web.bind.annotation.RequestMethod;
26+
import org.springframework.web.bind.annotation.PostMapping;
2827
import org.springframework.web.bind.annotation.ResponseBody;
2928

3029
/**
@@ -39,7 +38,7 @@ public ShutdownMvcEndpoint(ShutdownEndpoint delegate) {
3938
super(delegate);
4039
}
4140

42-
@RequestMapping(method = RequestMethod.POST)
41+
@PostMapping
4342
@ResponseBody
4443
@Override
4544
public Object invoke() {

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/EndpointHandlerMappingTests.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
import org.springframework.mock.web.MockHttpServletRequest;
2828
import org.springframework.util.ReflectionUtils;
2929
import org.springframework.web.HttpRequestMethodNotSupportedException;
30-
import org.springframework.web.bind.annotation.RequestMapping;
31-
import org.springframework.web.bind.annotation.RequestMethod;
30+
import org.springframework.web.bind.annotation.PostMapping;
3231
import org.springframework.web.method.HandlerMethod;
3332

3433
import static org.assertj.core.api.Assertions.assertThat;
@@ -168,7 +167,7 @@ private static class TestActionEndpoint extends EndpointMvcAdapter {
168167
}
169168

170169
@Override
171-
@RequestMapping(method = RequestMethod.POST)
170+
@PostMapping
172171
public Object invoke() {
173172
return null;
174173
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@
9090
import org.springframework.test.util.ReflectionTestUtils;
9191
import org.springframework.util.LinkedMultiValueMap;
9292
import org.springframework.util.MultiValueMap;
93-
import org.springframework.web.bind.annotation.RequestMapping;
94-
import org.springframework.web.bind.annotation.RequestMethod;
93+
import org.springframework.web.bind.annotation.GetMapping;
94+
import org.springframework.web.bind.annotation.PostMapping;
9595
import org.springframework.web.bind.annotation.RestController;
9696
import org.springframework.web.client.RestTemplate;
9797

@@ -191,7 +191,8 @@ public void testClientIsNotAuthCode() {
191191
EnvironmentTestUtils.addEnvironment(context,
192192
"security.oauth2.client.clientId=client");
193193
context.refresh();
194-
assertThat(countBeans(context, ClientCredentialsResourceDetails.class)).isEqualTo(1);
194+
assertThat(countBeans(context, ClientCredentialsResourceDetails.class))
195+
.isEqualTo(1);
195196
context.close();
196197
}
197198

@@ -465,13 +466,13 @@ protected static class ResourceServerConfiguration extends TestSecurityConfigura
465466
@RestController
466467
protected static class TestWebApp {
467468

468-
@RequestMapping(value = "/securedFind", method = RequestMethod.GET)
469+
@GetMapping("/securedFind")
469470
@PreAuthorize("#oauth2.hasScope('read')")
470471
public String secureFind() {
471472
return "You reached an endpoint secured by Spring Security OAuth2";
472473
}
473474

474-
@RequestMapping(value = "/securedSave", method = RequestMethod.POST)
475+
@PostMapping("/securedSave")
475476
@PreAuthorize("#oauth2.hasScope('write')")
476477
public String secureSave() {
477478
return "You reached an endpoint secured by Spring Security OAuth2";

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
import org.springframework.test.context.junit4.SpringRunner;
5050
import org.springframework.validation.BindException;
5151
import org.springframework.web.bind.MethodArgumentNotValidException;
52+
import org.springframework.web.bind.annotation.PostMapping;
5253
import org.springframework.web.bind.annotation.RequestBody;
5354
import org.springframework.web.bind.annotation.RequestMapping;
54-
import org.springframework.web.bind.annotation.RequestMethod;
5555
import org.springframework.web.bind.annotation.ResponseStatus;
5656
import org.springframework.web.bind.annotation.RestController;
5757
import org.springframework.web.servlet.View;
@@ -263,7 +263,7 @@ public String bind() throws Exception {
263263
throw error;
264264
}
265265

266-
@RequestMapping(path = "/bodyValidation", method = RequestMethod.POST, produces = "application/json")
266+
@PostMapping(path = "/bodyValidation", produces = "application/json")
267267
public String bodyValidation(@Valid @RequestBody DummyBody body) {
268268
return body.content;
269269
}

spring-boot-deployment-tests/spring-boot-deployment-test-glassfish/src/main/java/sample/SampleController.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,13 +16,13 @@
1616

1717
package sample;
1818

19-
import org.springframework.web.bind.annotation.RequestMapping;
19+
import org.springframework.web.bind.annotation.GetMapping;
2020
import org.springframework.web.bind.annotation.RestController;
2121

2222
@RestController
2323
public class SampleController {
2424

25-
@RequestMapping("/")
25+
@GetMapping("/")
2626
public String hello() {
2727
return "Hello World";
2828
}

spring-boot-deployment-tests/spring-boot-deployment-test-tomcat/src/main/java/sample/SampleController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-boot-deployment-tests/spring-boot-deployment-test-tomee/src/main/java/sample/SampleController.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,13 +16,13 @@
1616

1717
package sample;
1818

19-
import org.springframework.web.bind.annotation.RequestMapping;
19+
import org.springframework.web.bind.annotation.GetMapping;
2020
import org.springframework.web.bind.annotation.RestController;
2121

2222
@RestController
2323
public class SampleController {
2424

25-
@RequestMapping("/")
25+
@GetMapping("/")
2626
public String hello() {
2727
return "Hello World";
2828
}

spring-boot-deployment-tests/spring-boot-deployment-test-wildfly/src/main/java/sample/SampleController.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,13 +16,13 @@
1616

1717
package sample;
1818

19-
import org.springframework.web.bind.annotation.RequestMapping;
19+
import org.springframework.web.bind.annotation.GetMapping;
2020
import org.springframework.web.bind.annotation.RestController;
2121

2222
@RestController
2323
public class SampleController {
2424

25-
@RequestMapping("/")
25+
@GetMapping("/")
2626
public String hello() {
2727
return "Hello World";
2828
}

spring-boot-samples/spring-boot-sample-actuator-log4j2/src/main/java/sample/actuator/log4j2/SampleController.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121

2222
import org.springframework.beans.factory.annotation.Autowired;
2323
import org.springframework.stereotype.Controller;
24+
import org.springframework.web.bind.annotation.GetMapping;
2425
import org.springframework.web.bind.annotation.RequestMapping;
2526
import org.springframework.web.bind.annotation.ResponseBody;
2627

@@ -30,7 +31,7 @@ public class SampleController {
3031
@Autowired
3132
private HelloWorldService helloWorldService;
3233

33-
@RequestMapping("/")
34+
@GetMapping("/")
3435
@ResponseBody
3536
public Map<String, String> helloWorld() {
3637
return Collections.singletonMap("message",

spring-boot-samples/spring-boot-sample-actuator-ui/src/main/java/sample/actuator/ui/SampleActuatorUiApplication.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
import org.springframework.boot.autoconfigure.security.SecurityProperties;
2525
import org.springframework.context.annotation.Bean;
2626
import org.springframework.stereotype.Controller;
27+
import org.springframework.web.bind.annotation.GetMapping;
2728
import org.springframework.web.bind.annotation.RequestMapping;
2829

2930
@SpringBootApplication
3031
@Controller
3132
public class SampleActuatorUiApplication {
3233

33-
@RequestMapping("/")
34+
@GetMapping("/")
3435
public String home(Map<String, Object> model) {
3536
model.put("message", "Hello World");
3637
model.put("title", "Hello Home");

spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleController.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,8 +27,9 @@
2727
import org.springframework.context.annotation.Description;
2828
import org.springframework.stereotype.Controller;
2929
import org.springframework.validation.annotation.Validated;
30+
import org.springframework.web.bind.annotation.GetMapping;
31+
import org.springframework.web.bind.annotation.PostMapping;
3032
import org.springframework.web.bind.annotation.RequestMapping;
31-
import org.springframework.web.bind.annotation.RequestMethod;
3233
import org.springframework.web.bind.annotation.ResponseBody;
3334

3435
@Controller
@@ -38,14 +39,14 @@ public class SampleController {
3839
@Autowired
3940
private HelloWorldService helloWorldService;
4041

41-
@RequestMapping(value = "/", method = RequestMethod.GET)
42+
@GetMapping("/")
4243
@ResponseBody
4344
public Map<String, String> hello() {
4445
return Collections.singletonMap("message",
4546
this.helloWorldService.getHelloMessage());
4647
}
4748

48-
@RequestMapping(value = "/", method = RequestMethod.POST)
49+
@PostMapping("/")
4950
@ResponseBody
5051
public Map<String, Object> olleh(@Validated Message message) {
5152
Map<String, Object> model = new LinkedHashMap<String, Object>();

spring-boot-samples/spring-boot-sample-data-jpa/src/main/java/sample/data/jpa/web/SampleController.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2013 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
2121
import org.springframework.beans.factory.annotation.Autowired;
2222
import org.springframework.stereotype.Controller;
2323
import org.springframework.transaction.annotation.Transactional;
24-
import org.springframework.web.bind.annotation.RequestMapping;
24+
import org.springframework.web.bind.annotation.GetMapping;
2525
import org.springframework.web.bind.annotation.ResponseBody;
2626

2727
@Controller
@@ -30,7 +30,7 @@ public class SampleController {
3030
@Autowired
3131
private CityService cityService;
3232

33-
@RequestMapping("/")
33+
@GetMapping("/")
3434
@ResponseBody
3535
@Transactional(readOnly = true)
3636
public String helloWorld() {

spring-boot-samples/spring-boot-sample-devtools/src/main/java/sample/devtools/MyController.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,13 +22,13 @@
2222

2323
import org.springframework.stereotype.Controller;
2424
import org.springframework.ui.ModelMap;
25-
import org.springframework.web.bind.annotation.RequestMapping;
25+
import org.springframework.web.bind.annotation.GetMapping;
2626
import org.springframework.web.servlet.ModelAndView;
2727

2828
@Controller
2929
public class MyController {
3030

31-
@RequestMapping("/")
31+
@GetMapping("/")
3232
public ModelAndView get(HttpSession session) {
3333
Object sessionVar = session.getAttribute("var");
3434
if (sessionVar == null) {

spring-boot-samples/spring-boot-sample-hateoas/src/main/java/sample/hateoas/web/CustomerController.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
import org.springframework.http.MediaType;
2929
import org.springframework.http.ResponseEntity;
3030
import org.springframework.stereotype.Controller;
31+
import org.springframework.web.bind.annotation.GetMapping;
3132
import org.springframework.web.bind.annotation.PathVariable;
3233
import org.springframework.web.bind.annotation.RequestMapping;
33-
import org.springframework.web.bind.annotation.RequestMethod;
3434

3535
@Controller
3636
@RequestMapping("/customers")
@@ -46,15 +46,15 @@ public CustomerController(CustomerRepository repository, EntityLinks entityLinks
4646
this.entityLinks = entityLinks;
4747
}
4848

49-
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
49+
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
5050
HttpEntity<Resources<Customer>> showCustomers() {
5151
Resources<Customer> resources = new Resources<Customer>(
5252
this.repository.findAll());
5353
resources.add(this.entityLinks.linkToCollectionResource(Customer.class));
5454
return new ResponseEntity<Resources<Customer>>(resources, HttpStatus.OK);
5555
}
5656

57-
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
57+
@GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
5858
HttpEntity<Resource<Customer>> showCustomer(@PathVariable Long id) {
5959
Resource<Customer> resource = new Resource<Customer>(this.repository.findOne(id));
6060
resource.add(this.entityLinks.linkToSingleResource(Customer.class, id));

spring-boot-samples/spring-boot-sample-hibernate4/src/main/java/sample/hibernate4/web/SampleController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.springframework.beans.factory.annotation.Autowired;
2222
import org.springframework.stereotype.Controller;
2323
import org.springframework.transaction.annotation.Transactional;
24-
import org.springframework.web.bind.annotation.RequestMapping;
24+
import org.springframework.web.bind.annotation.GetMapping;
2525
import org.springframework.web.bind.annotation.ResponseBody;
2626

2727
@Controller
@@ -30,7 +30,7 @@ public class SampleController {
3030
@Autowired
3131
private CityService cityService;
3232

33-
@RequestMapping("/")
33+
@GetMapping("/")
3434
@ResponseBody
3535
@Transactional(readOnly = true)
3636
public String helloWorld() {

0 commit comments

Comments
 (0)