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
69
votes
4 answers

When looking at the differences between X-Auth-Token vs Authorization headers, which is preferred?

What is the difference between the two headers below? Which one is preferred? X-Auth-Token : dadas123sad12 Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Deepak
  • 741
  • 1
  • 5
  • 13
62
votes
17 answers

@RequestBody is getting null values

I have created a simple REST service (POST). But when i call this service from postman @RequestBody is not receiving any values. import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestBody; import…
Geek
  • 1,214
  • 5
  • 14
  • 27
58
votes
3 answers

Difference between path and value attributes in @RequestMapping annotation

What is the difference between below two attributes and which one to use when? @GetMapping(path = "/usr/{userId}") public String findDBUserGetMapping(@PathVariable("userId") String userId) { return "Test User"; } @RequestMapping(value =…
Raj
  • 2,463
  • 10
  • 36
  • 52
57
votes
3 answers

Reading HTTP headers in a Spring REST controller

I am trying to read HTTP headers in Spring based REST API. I followed this. But I am getting this error: No message body reader has been found for class java.lang.String, ContentType: application/octet-stream I am new to Java and Spring so can't…
Ashwani K
  • 7,880
  • 19
  • 63
  • 102
54
votes
7 answers

Return HTTP 204 on null with spring @RestController

This returns 200 OK with Content-Length: 0 @RestController public class RepoController { @RequestMapping(value = "/document/{id}", method = RequestMethod.GET) public Object getDocument(@PathVariable long id) { return null; …
user1606576
  • 1,062
  • 2
  • 11
  • 11
50
votes
2 answers

Exception message not included in response when throwing ResponseStatusException in Spring Boot

My Spring Boot application provides the following REST controller: @RestController @RequestMapping("/api/verify") public class VerificationController { final VerificationService verificationService; Logger logger =…
Robert Strauch
  • 12,055
  • 24
  • 120
  • 192
48
votes
7 answers

Could not verify the provided CSRF token because your session was not found in spring security

I am using spring security along with java config @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/api/*").hasRole("ADMIN") .and() .addFilterAfter(new…
Haseeb Wali
  • 1,181
  • 3
  • 14
  • 34
41
votes
8 answers

upload file springboot Required request part 'file' is not present

I want to add an upload function to my spring boot application; this is my upload Rest Controller package org.sid.web; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import…
Wintern
  • 413
  • 1
  • 4
  • 5
38
votes
4 answers

Which layer should be used for conversion to DTO from Domain Object

We are creating rest api's with Spring Boot. We have three layers in our project(Repository, Service and Controller). Lets say I have GetUser api in my controller that return UserDTO object. @GetMapping public UserDTO getUser() { return…
Suleyman Arıkan
  • 503
  • 1
  • 4
  • 7
38
votes
12 answers

@RestController in other package doesn't work

I start with learning Spring and I create basic project which creates database, insert values and next print it in web browser. My problem is that when I have RestController in the same package like main class - its OK, but I want distribute it to…
CeZet
  • 1,473
  • 5
  • 22
  • 44
33
votes
2 answers

Does Spring create new thread per request in rest controllers?

I wanted to learn non blocking REST, but first I wrote blocking controller for comparison. To my surprise Spring doesn't block incoming requests. Simple blocking service: @Service public class BlockingService { public String blocking() { …
user
  • 4,410
  • 16
  • 57
  • 83
32
votes
4 answers

Spring Boot can't autowire @ConfigurationProperties

Here is my FileStorageProperties class: @Data @ConfigurationProperties(prefix = "file") public class FileStorageProperties { private String uploadDir; } This gives me saying : not registered via @enableconfigurationproperties or marked…
31
votes
2 answers

org.apache.catalina.connector.ClientAbortException: java.io.IOException: APR error: -32

At my Spring Boot + Tomcat 8 project I have configured @ControllerAdvice which looks like: @ControllerAdvice public class GlobalControllerExceptionHandler { final static Logger logger =…
alexanoid
  • 24,051
  • 54
  • 210
  • 410
26
votes
6 answers

How to create a Spring Interceptor for Spring RESTful web services

I have some Spring RESTful (RestControllers) web services with no web.xml and I am using Spring boot to start the services. I want to add authorization layer for the web services and wanted to route all the http requests to one front controller…
Praneeth Reddy
  • 393
  • 1
  • 4
  • 7
26
votes
7 answers

Avoiding default basic-error-controller from swagger api

I'm using swagger2 in my spring boot project. It's working well, but I need to exclude the basic-error-controller from the api. Currently I'm using the following code using regex. It's working but is there any perfect way to do this. CODE…
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
1
2 3
99 100