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
5
votes
3 answers

@JsonProperty not working for Content-Type : application/x-www-form-urlencoded

The REST API takes input content type : application/x-www-form-urlencoded, when it is mapped to a Java Object, like public class MyRequest { @JsonProperty("my_name") private String myName; @JsonProperty("my_phone") private String…
Vineet Singla
  • 1,609
  • 2
  • 20
  • 34
5
votes
1 answer

how do I allow only one session to Spring REST web service at one time?

I have a spring REST web service URL http://localhost:8080/MySpringRestService/callSome How can I restrict concurrent access to web service. My requirement is to allow only one request to web service at one time. Any kind of help would be…
tinlinnsoe
  • 196
  • 1
  • 2
  • 13
5
votes
1 answer

Test spring rest controller secured with https

Can anybody provide me with a code sample to write integration test for a controller which is secured with HTTPS?? With HTTP I am able to write, but with HTTPS I am getting certification…
Pratap A.K
  • 4,337
  • 11
  • 42
  • 79
4
votes
1 answer

Strange Security Error in Spring Boot 3.0.2

I have a very strange security issue in Spring Boot 3.0.2 When I try to secure a REST service with @PreAuthorize and the method contains parameters I get the following error message: Name for argument of type [int] not specified, and parameter name…
4
votes
1 answer

Spring boot (.2.3.0.RELEASE) with bucket4j rate limit not working

I am trying to use limit rate API for a Spring Boot Rest application, with bucket4j based on the following online resource Please find my configuration below: Below is maven dependency added to use 4bucketj: ...
user1999453
  • 1,297
  • 4
  • 29
  • 65
4
votes
0 answers

Feign client method and java.lang.IllegalArgumentException: Body parameter 1 was null

I have the following Feign client method: @GetMapping RestPageImpl findAllCompanies(@RequestParam(value = "name", required = false) String name, Pageable pageable, @RequestHeader("Authorization") String token); everything works fine…
alexanoid
  • 24,051
  • 54
  • 210
  • 410
4
votes
2 answers

How do I configure @PreAuthorize to recognize the ID of my logged in user?

I'm trying to create a Spring Boot 2.1 application. I have created the following rest controller ... @RestController @RequestMapping("/api/users") public class UserController { ... @PutMapping("/{id}") …
4
votes
1 answer

Using AtomicLong in a REST Controller

Is the atomic integer in the following piece of code shared between different REST calls? What if it was static? public class GreetingController { private static final String template = "Hello Docker, %s!"; private final AtomicLong counter…
Arian
  • 7,397
  • 21
  • 89
  • 177
4
votes
1 answer

RestController - Forward POST request to external URL

I'm looking for a way how to forward POST request which has been made to endpoint in @RestController class and forward it to external URL with body and headers untouched (and return response from this API of course), is it possible to do it by using…
Kamil W
  • 2,230
  • 2
  • 21
  • 43
4
votes
0 answers

How to use Spring REST HATEOAS from Angular?

I was learning about Spring REST HATEOAS. But, I am confused about how we use it on the client end.. I mean, let's say I want write a client app using Angular JS. So now I don't have to hardcode the URL's to make REST API calls? And instead i'd use…
rakesh mehra
  • 618
  • 1
  • 9
  • 21
4
votes
2 answers

Could not write JSON:Infinite recursion(StackOverflowError)nested exception is com.fasterxml.jackson.databind.JsonMappingException:Infinite recursion

I've developed Spring Boot + Spring Data Jpa Rest example. I developed below code and giving me below error, with that code even I am not able to launch the Swagger giving me error. { "timestamp": "2019-07-22T15:29:04.487+0000", "status":…
PAA
  • 1
  • 46
  • 174
  • 282
4
votes
1 answer

Enums as Request Parameters in Spring Boot Rest

I am new to spring boot and trying to use Enum as a parameter of a rest request. This is my Enum class: public enum Month { JANUARY (1, "january"), FEBRUARY(2,"february"), MARCH(3,"march"), APRIL(4,"april"), MAY(5,"may"), JUNE(6,"june"),…
user6941415
4
votes
2 answers

Add binding for validation

I want to create Spring endpoint for validating Java Object. I tried to implement this example: https://www.baeldung.com/validation-angularjs-spring-mvc I tried this: public class WpfPaymentsDTO { @NotNull @Size(min = 4, max = 15) …
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
4
votes
1 answer

Spring webflux controller: consuming POJO vs Mono?

In a controller I can write: fun update(@RequestBody myPojo: MyPojo): Mono or fun update(@RequestBody myPojo: Mono): Mono is there any difference? will the body parsing be done in different threads? in first case will i…
piotrek
  • 13,982
  • 13
  • 79
  • 165
4
votes
6 answers

How to send Integer value in the form of JSON format and recieve in REST Controller?

I have one REST Controller where I have written this code @PostMapping(value = "/otp") public void otp(@RequestBody Integer mobile) { System.out.println(" Mobile = "+mobile); } And I am calling this method from Postman with the following…
Altaf Ansari
  • 726
  • 2
  • 7
  • 18