Questions tagged [spring-restcontroller]

@RestController is Spring MVC's shortcut annotation for creating Rest Controllers. Use this tag for questions relating to the use of this annotation.

@RestController is an Spring annotation that is used to declare controllers where all @RequestMapping annotated methods assume @ResponseBody semantics by default.

Useful links:

1579 questions
6
votes
2 answers

Get values from MultiValueMap

I use this code to get values from an HTTP request: @PostMapping(consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, value = "/v1/notification") public ResponseEntity handleNotifications(@RequestBody MultiValueMap
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
6
votes
1 answer

Calling Spring controller method without going to internet

tldr: Is there a way to make an internal request (using the method's path) without going to the internet? -- Why do I need it? I have a project which receives many events. The decision of who will handle each event is made by a Controller. So I have…
Rômulo M. Farias
  • 1,483
  • 1
  • 15
  • 29
6
votes
3 answers

How to profile complex http request handling in Spring Boot?

I have complex @RestController method, something like this: @PostMapping("{id}") @PreAuthorize("hasRole('ADMIN')") @Transactional public Response handleRequest(@PathVariable("id") long id, @RequestBody @Valid Request request) { return…
Sankozi
  • 500
  • 5
  • 22
6
votes
4 answers

How to handle exception thrown by object in @Requestbody in spring boot 2

I have a rest controller class as follows which throws custom exception when user object is invalid. But those exception got wrapped by spring framework and not handled by the specific exception handler defined in controller…
6
votes
6 answers

In the context of SpringMVC, how to have web services that provide different JSON representation of a same class?

I have a data class, something like this: public class Person { private String name; private Long code; // corresponding getters and setters } I want to write two web services that provide two different JSON representation of Person. For…
vahidreza
  • 843
  • 1
  • 8
  • 19
6
votes
3 answers

Custom @ControllerAdvice in Spring for exception handling

I am trying to map exceptions from my rest controllers to responses which have a body, and to do it in a central place. I have tried this: @Order(Ordered.HIGHEST_PRECEDENCE) @ControllerAdvice public class RestErrorResponseExceptionHandler…
ioreskovic
  • 5,531
  • 5
  • 39
  • 70
6
votes
3 answers

Difference between parameters taken by @RestController and @RequestMapping annotations?

What does the parameter in @RestController("/path/..") do? Does it not set the base path like @RequestMapping("/path/.."). What is the difference? @RestController("base-path")
Kranthi
  • 133
  • 2
  • 10
6
votes
0 answers

Delete tmp file after response?

My use case: On user request create tmp file (I don't really need to create real file, but I need to have java.io.File instance) Process this file Return file and other meta data as json Remove tmp file permanently My code looks…
Andrew Sasha
  • 1,254
  • 1
  • 11
  • 21
6
votes
1 answer

Log request payload in Spring Boot

How can we log request payload/parameters before and after processing in filter of spring boot application. For example: /api/users/auth Body: `name:Vijay, place:bangalore...` I have to log request body in filter before and after processing the…
user8630128
6
votes
2 answers

Spring @RequestMapping absolute path

I've a RestController for a CRUD annotated like this: @RestController @RequestMapping("/rest/v1/area") public class AreaController My methods are annotated like: @RequestMapping(value = "/{uuid}", method = RequestMethod.PUT) public…
Germán
  • 328
  • 6
  • 15
6
votes
4 answers

How to return plain text in spring controller?

I want to return a simple plain text string as follows: @RestController @RequestMapping("/test") public class TestController { @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/my", method = RequestMethod.GET, produces="text/plain") …
membersound
  • 81,582
  • 193
  • 585
  • 1,120
6
votes
1 answer

Annotations for feature flipping REST end points

I have spring controller with several (REST) endpoints. I want to bring up multiple instances of this controller where each instance would have few endpoints selectively enabled/disabled. Based on my reading so far, togglz provides feature…
mobileDev
  • 1,358
  • 2
  • 14
  • 34
6
votes
1 answer

SpringBoot, limit request size of a PUT request

I'm running a spring-boot service with an embed tomcat container. Is there a way to limit the size of a HTTP PUT request via common application properties or EmbeddedServletContainerFactory? Thanks
6
votes
3 answers

How to implement Spring Security 4 with both XML and Java config

I am trying to implement Spring-Security 4 into my Spring MVC web and rest app. I added 2 classes to enable Spring Security the java config way. I still want to hold onto my web.xml and not change the entire project to use java config. As soon as…
logixplayer
  • 939
  • 2
  • 13
  • 23
5
votes
1 answer

Spring Pageable Sort change name of property

Is there a way to map properties of Sort objects? Just a little example: a Dto public class OrderDto { private long totalAmount; private long openAmount; } and an entity @Entity public class Order { private long amount; } and a…
kaputnix
  • 123
  • 10