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

What is the best practice for RestController?

Code convention says no logic in the controllers. All should be handled in the service layer. My question is especially about returning ResponseEntity. Should it be handled in RestController or in Service layer? I tried both ways. I think…
Cihangir
  • 1,892
  • 1
  • 11
  • 16
15
votes
7 answers

nested exception is java.lang.IllegalArgumentException: Not a managed type: class

I am trying to deploy a Spring-Boot application with Service accessing a JpaRepository which is connecting to PostgreSQL DB at runtime using JPA and Hibernate, refering to connection properties in src/main/resources/application.properties When I am…
14
votes
3 answers

415 Unsupported MediaType for POST request in spring application

I have a very simple Spring Application (NOT spring boot). I have implemented a GET and POST controller methods. the GET method works fine. But the POST is throwing 415 Unsupported MediaType. Steps to reproduce are available below ServiceController.…
brain storm
  • 30,124
  • 69
  • 225
  • 393
14
votes
8 answers

Spring Boot binding and validation error handling in REST controller

When I have the following model with JSR-303 (validation framework) annotations: public enum Gender { MALE, FEMALE } public class Profile { private Gender gender; @NotNull private String name; ... } and the following JSON…
14
votes
2 answers

Spring MVC RestController scope

I have the following Spring controller: package hello; import java.util.concurrent.atomic.AtomicLong; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import…
Babu James
  • 2,740
  • 4
  • 33
  • 50
13
votes
2 answers

Spring @GetMapping with @RequestParam and @RequestBody fails with HttpMessageNotReadableException

Request to the endpoint fails with the following error: 400 Bad request org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing @GetMapping public List list(@RequestParam(required =…
Ilya Buziuk
  • 1,839
  • 5
  • 27
  • 43
12
votes
1 answer

How To Stream Chunked Response With Spring Boot @RestController

I have spent like a day on this and I am unable to find a solution that works. In our application we have a couple of endpoints that can return large responses. I have been trying to find a mechanism that allows us to stream the response as we…
sceaj
  • 1,573
  • 3
  • 12
  • 24
12
votes
3 answers

JSON Patch Request validation in Java

In my spring boot service, I'm using https://github.com/java-json-tools/json-patch for handling PATCH requests. Everything seems to be ok except a way to avoid modifying immutable fields like object id's, creation_time etc. I have found a similar…
shoaib1992
  • 410
  • 1
  • 8
  • 26
12
votes
11 answers

Rest Controller not recognizing GET request in Spring Boot App

I am trying to implement simple demo MVC app with Spring Boot but I get 404 error while executing the application. The uri is `http://localhost:8080/' which is to display all the rows in a table called circle. Spring Boot : 1.3.3.RELEASE Java…
gkc123
  • 512
  • 1
  • 7
  • 24
11
votes
2 answers

Redirection inside reactive Spring Webflux REST controller

I'm creating simple controller server for spring reactive project. While setting redirection to another location, I have found an error when calling http://localhost:8080/: There was an unexpected error (type=Internal Server Error,…
11
votes
5 answers

InvalidDefinitionException: Cannot construct instance of `com.vehicle.datatransferobject.VehicleDTO`

In the REST endpoint I'm building in Spring Boot, I'm trying to pass my vehicleDTO to my controller. But before it reaches my controller, there is an error. InvalidDefinitionException: Cannot construct instance of …
RK3
  • 1,221
  • 9
  • 26
  • 37
11
votes
2 answers

Resttemplate and patch, invalid

I use spring 1.4.3 I try to call a web service @PatchMapping(value = "/members/{memberId}/card") public ResponseEntity updateMemberCardId(@PathVariable("memberId") Long memberId, @RequestBody String cardId) throws ResourceNotFoundException { …
robert trudel
  • 5,283
  • 17
  • 72
  • 124
11
votes
1 answer

How to handle maximum file size Exception in Spring Boot?

I am using Spring Boot v1.2.5 for creating a REST Application. While uploading images, I have a check for maximum file size , which is provided the property : multipart.maxFileSize= 128KB in application.properties. This facility is provided by…
de_xtr
  • 882
  • 2
  • 10
  • 21
11
votes
2 answers

Using a map to set parameters for a rest call using RestTemplate

I am currently using a piece of code to set parameters and I do a REST call to a URL using restTemplate, it works fine: MultiValueMap map = new LinkedMultiValueMap(); map.add("grant_type",…
Emilien Brigand
  • 9,943
  • 8
  • 32
  • 37
10
votes
1 answer

JSON parse error: Can not construct instance of class

Unable to map json string with java object, getting error JSON parse error: Can not construct instance of com.test.CPInput$Evc$Uni error: { "timestamp": 1502270576300, "status": 400, "error": "Bad Request", "exception":…
2787184
  • 3,749
  • 10
  • 47
  • 81