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
8
votes
1 answer

springdoc-openapi-ui + swagger don't understand @PathVariable required = false flag

I use this library for generation documentation: org.springdoc springdoc-openapi-ui 1.5.0 I have this controller: @RestController public class…
8
votes
3 answers

Spring - is it possible to give same url (path) in request mapping for two different post methods?

Is it possible to map same path (uri) in request mapping for two different post methods, only difference is request body. Example @RequestMapping(value = "/hello", method = RequestMethod.POST) public String helloEmployee(@RequestBody Employee…
Ravikumar
  • 413
  • 1
  • 7
  • 18
8
votes
1 answer

GetMapping to produce CSV file using Spring Boot

I'm writing a spring rest method to get details from database and set it in a response POJO and then return it. Currently I need to produce this response in CSV instead of default json when the URL is hit using POSTMAN or RC like a downloadable CSV…
user2632905
  • 237
  • 2
  • 3
  • 12
8
votes
5 answers

XmlElement(name="custom_name") not working in spring boot integrated with rest services

I am almost new to rest services world,here i am trying to change the field name displayed in the output xml. Not sure,am i following the right method,any help is a good thing. Activity.java import javax.xml.bind.annotation.XmlAccessType; import…
Prash
  • 544
  • 8
  • 24
8
votes
2 answers

How to consume protobuf parameters using Spring REST?

I'm trying to pass a protobuf parameter to a REST endpoint but I get org.springframework.web.client.HttpServerErrorException: 500 null each time I try. What I have now is something like this: @RestController public class TestTaskEndpoint { …
Adam Arold
  • 29,285
  • 22
  • 112
  • 207
8
votes
0 answers

Spring REST Upload file as binary

I'm using spring. I want to implement rest controller to upload file to server. I found a lot examples like this: public ResponseEntity doSomething(@PathVariable String paramOne, @RequestParam(required = false, name="file") List
user2281439
  • 673
  • 2
  • 11
  • 19
8
votes
2 answers

Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException:

i have some problem with my constructor in one my controller. I try to call one service in a constructor. The Service is autowired in an AbstractController, but i got a nullpointer exception. A…
emoleumassi
  • 4,881
  • 13
  • 67
  • 93
8
votes
2 answers

Spring restController: how to error when unknown @RequestParam is in url

I'm using spring 4.2 to create some restfull webservices. But we realized that when a user mistypes one of the not-mandatory @RequestParam, we do not get an error that the param he passed is unknown. like we have @RequestParam(required=false,…
user4768018
  • 131
  • 1
  • 3
7
votes
3 answers

Spring-boot + REST + HATEOAS + HAL

I followed the spring.io Pivotal tutorials to get a REST API with a MySQL DB off the ground and things are progressing nicely. However I found a behavior that I haven't been able to configure or work around. When I use the built-in functionality to…
ETN
  • 73
  • 1
  • 4
7
votes
2 answers

How do I convert request body in a @RestController to a List of abstract values?

Let's say we have the following classes: public abstract class Investment { private String investmentType; // getters & setters } public class Equity extends Investment { } public class Bond extends Investment { } public class…
dukethrash
  • 1,449
  • 4
  • 15
  • 25
7
votes
1 answer

Spring : Auto Generate CRUD Rest Controller

Is there a way to generate spring rest crontroller for a business flow. I want to generate CRUD services for given database object.For example, "employee_mst" , generate CRUD services code automatically.This is similar to what we used to have in…
Allzhere
  • 1,280
  • 1
  • 11
  • 19
7
votes
1 answer

Paging results of aggregation pipeline with spring data mongodb

I am having a bit of trouble with paging the results of an aggregation pipeline. After looking at In spring data mongodb how to achieve pagination for aggregation I came up with what feels like a hacky solution. I first performed the match query,…
7
votes
2 answers

spring MVC controller versioning

I have a spring boot application , which have a spring MVC controller. I am trying to version my rest api using Accept header. The following is how my Controller looks like RestController @RequestMapping(value = "/private/") public class…
Prabhakar D
  • 1,084
  • 2
  • 15
  • 35
7
votes
1 answer

How to test with MockMVC a Map parameter in Spring Rest

In Spring Rest, I have a RestController exposing this method: @RestController @RequestMapping("/controllerPath") public class MyController{ @RequestMapping(method = RequestMethod.POST) public void create(@RequestParameter("myParam")…
Rémi Doolaeghe
  • 2,262
  • 3
  • 31
  • 50
6
votes
2 answers

Spring security 6.0 AuthorizationFilter - questionable default for shouldFilterAllDispatcherTypes

I spent a few hours today on a migration issue to Spring security 6.0 by replacing the deprecated authorizeRequests() method with authorizeHttpRequests(). I learned that under the hood, this implies replacing the FilterSecurityInterceptor with the…