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

Spring Rest Controller - Can I allow allow CORS in the interceptor?

I have an interceptor: @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new RequestInterceptor()); } Can I add my CORS configuration in the RequestInterceptor.java above? Like…
BrownRecluse
  • 1,638
  • 1
  • 16
  • 19
3
votes
2 answers

Spring REST add field to 404 resonse code

Using latest Spring Boot as of May 2018. I've created a 404 response like this. @ResponseStatus(HttpStatus.NOT_FOUND) public class NotFoundException extends RuntimeException { private final int errorId; public NotFoundException(String…
Vering
  • 907
  • 9
  • 19
3
votes
0 answers

Spring REST service hangs up when forwarding a ResponseEntity

I am facing a problem using a REST service made up with Spring Boot 1.5. I am developing a REST service that acts as a proxy, forwarding requests to another REST service that exposes the same API. @RestController @RequestMapping("/user") public…
riccardo.cardin
  • 7,971
  • 5
  • 57
  • 106
3
votes
2 answers

Protect Actuator endpoints with user/password while granting public access for RestControllers

I updated an already existing application from Spring Boot 1.3 to 2.0.1. This application makes use of the Actuator and exposes a REST-style API. In Boot 1.3 the API could be used without authentication and the actuator endpoint was configured to be…
3
votes
2 answers

Spring boot Maven MultiModule Rest api Call

All I'm new on Spring boot and have a question. Currently I'm working with the spring boot multi module project. I have 3 spring boot project. like A,B,C, each have rest-controller like…
Nabeel Ahmed
  • 258
  • 1
  • 7
  • 23
3
votes
1 answer

Spring Boot Swagger: How to ignore certain API's from swagger based on spring profile?

Currently, there are certain private API's in my controller class which I need to ignore them in my production environment, whereas needed in the QA and Dev environments. I'm using @ApiIgnore annotation from spring fox to achieve this on a global…
3
votes
3 answers

How to set the produces value dynamically in spring rest controller?

I need to implement API which can either send response or download a file: @GetMapping(value = "/download") public ResponseEntity downloadFile( @RequestParam(value = "apiResponseType", required = true) String apiResponseType) throws…
Krish
  • 1,804
  • 7
  • 37
  • 65
3
votes
0 answers

Spring Boot: handling SizeLimitExceededException always gives "SocketException: Software caused connection abort: recv failed" in RestTemplate

I'm using Spring boot 1.5.10. I have a RestController that handles file uploads, which I'm calling from another process using RestTemplate. When the file I'm trying to upload is too big, Tomcat triggers a…
3
votes
3 answers

Foreign Key is not getting saved in Spring Rest Application

I am trying to implement bidirectional one to many relationship using Spring Data JPA. I have created test cases for save and get data and there is no issue in the mapping and data is getting saved in both the tables. But when I am trying to create…
3
votes
1 answer

Angular 5: Sending POST request with string parameters and FormData parameter together, to a Spring REST Controller

I want to send a POST request from my service to a SpringBoot @RestController. I have a bunch of string parameters that I am sending, but I also have a FormData parameter which is an image (picture argument). If I do it like this: public…
fspasovski
  • 361
  • 2
  • 15
3
votes
3 answers

TimeoutException thrown when sending to topic

i have made sender class using kafkatemplate bean to send payload to topic with some configuration in SenderConfiguration class . Sender Class @Component public class Sender { private static final Logger LOGGER = (Logger) …
3
votes
3 answers

Optional @Pathvariable in REST controller spring 4

I'm writing a Rest Service (HTTP Get endpoint), where in the below uri does the following http://localhost:8080/customers/{customer_id} fetch the details for the customer_id passed in the uri if the customer_id is not passed…
technoJ
  • 175
  • 1
  • 1
  • 16
3
votes
2 answers

Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type:

I am trying to expose REST service, but while hitting it from POSTMAN i am getting below : WARNING: Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class…
3
votes
4 answers

Spring Boot 2.0.0.M4 and email address as @PathVariable gives HTTP 500 error

I'm trying to migrate from Spring Boot 1.5.7 to 2.0.0.M4 This is my rest controller: @RestController @RequestMapping("/v1.0/users") public class UsersController { @Autowired private UserService userService; @RequestMapping(value =…
alexanoid
  • 24,051
  • 54
  • 210
  • 410
3
votes
1 answer

Swagger - Render response status for declared exception

I'm doing my REST documentation with swagger. I've set it up and got access on SwaggerUi and also see all my configured REST resources with their supported methods. In my backend I have a ControllerAdvice, which does a global exception handling for…
Herr Derb
  • 4,977
  • 5
  • 34
  • 62