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

Why does the Rest Controller give an error : "No adapter for handler"?

I want to make a simple example of spring interacting with MongoDB. I have a product model: @NoArgsConstructor @ToString(exclude = {"id"}) public class Product { @Id private String id; private String name; private Integer price; …
Omegon
  • 387
  • 2
  • 10
2
votes
1 answer

Can not Send POST request to @RequestBody in Spring, error 415

I am working currently on a project and I need to send a POST request to spring. I looked or several hours already for a solution and didn't find one to work. The request worked when I developed that part. The problem is that after creating some new…
2
votes
1 answer

Catch all requested paths in Springboot RestController

I am looking for a way to get an Endpoint in Springboot that catches all requests send to /. Ideally everything behind / should be handed in as a String parameter. An example request could look like this: http://myproxy.com/foo/bar?blah=blubb I…
Tom
  • 3,807
  • 4
  • 33
  • 58
2
votes
1 answer

SpringDoc Problem With Methods With Different Query Parameters

I want to do something like create two method for same url pattern with different arguments @RequestMapping(value = "/searchUser", params = "userID") public String searchUserById(@RequestParam long userID, Model model) { //…
Mike Rother
  • 591
  • 4
  • 16
2
votes
2 answers

What is best practice in using @OneToMany relation with @RestController without infinite recutsion

I have following: @Data @Entity @Table(name = "floor") public class Floor { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) @Column(name = "floor_id") private Long id; @JsonIgnoreProperties(value= {"floor",…
2
votes
0 answers

Setters for session scoped bean not working in RestController

I'm trying to get the username from the session scoped bean once the user has logged in using /users/login I've Autowired a session scoped bean into a RestController and in one of the endpoints in the rest controller, I'm invoking a setter on the…
2
votes
1 answer

MockMvc tests always returns status code 200 for get requests

I I am very new to spring boot and only have been working with it for a couple of days, so I am also very confused about this project (which is not my own). I am supposed to write tests with MockMvc for the rest controller, however each test with…
cybel
  • 381
  • 2
  • 6
  • 16
2
votes
1 answer

How to return custom response in Spring with several attributes other than the List

I'm trying to get a custom response back from a spring rest controller back to the user, containing a list of all registered users and other keys such as sucess, etc. I tried the following approach but the Json array is completly escaped as a…
Eunito
  • 416
  • 5
  • 22
2
votes
1 answer

Java modules Jigsaw JPMS modularization prevents Spring container from starting rest controller because of org.apache.juli.logging.Log

I am having an issue after switching to Java 11 and adding modules to a Spring Boot application that acts as a REST API. I am not getting any errors when running the application and it shuts down after initialization with exit code 0. The Tomcat…
Radu Ionescu
  • 3,462
  • 5
  • 24
  • 43
2
votes
0 answers

How to configure Swagger 2 to work with Spring Web MVC (not Spring Boot)?

I've been trying to configure Swagger 2 with Spring MVC according to this tutorial. It works well with Spring Boot but not with Spring MVC. I don't even get any error messages. I just get "HTTP Status 404 – Not Found". I am working with Spring MVC…
2
votes
2 answers

Spring REST controller does not handle gzip compressed input

I have set up my spring boot application to handle HTTP server compression by setting the following properties in application.properties according to the…
sakra
  • 62,199
  • 16
  • 168
  • 151
2
votes
2 answers

Spring RestController returns wrong content type

I am trying to return an image in a Spring RestController in the following way: @GetMapping(path = "/images/{imageKey:.+}") public ResponseEntity getImageAsResource( @PathVariable("imageKey") String imageKey) { Resource…
sakra
  • 62,199
  • 16
  • 168
  • 151
2
votes
1 answer

Required request part 'file' is not present in Spring Boot

I checked all of the simular posts and still couldnt find the solution. Problem is Required request part 'file' is not present in test class. I want to upload a file and save it to the database. Here is my rest controller…
2
votes
1 answer

Double Type formatter in Spring REST

I have Model Class of Type Mileage That is declared as the following public class Mileage extends Entity { @JsonProperty("mileageValue") private double mileageValue; @JsonProperty("mileageTime") private long mileageTime; } and the…
abdo_mah90
  • 83
  • 1
  • 7
2
votes
2 answers

In Spring Boot 2, how do I construct a curl request to POST (create) an entity when it has foreign keys?

I'm using Spring Boot 2, Java 11, and PostGres 10. I have the following entity. Notice it has a couple of many-to-one foreign key constraints ... @Data @Entity @Table(name = "Cards") public class Card { @Id @GeneratedValue(strategy =…
satish
  • 703
  • 5
  • 23
  • 52