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

@GetMapping with array parameters by application.yml

I have developed this @GetMapping RestController and all works fine @GetMapping(path = {"foo", "bar"}) public ResponseEntity foobar() { return ResponseEntity.ok("foobar"); } now I want externalize the values inside the path array using…
Federico Gatti
  • 535
  • 1
  • 9
  • 22
4
votes
2 answers

Best way to limit time execution in a @RestController

Considering the following code: @RestController @RequestMapping("/timeout") public class TestController { @Autowired private TestService service; @GetMapping("/max10secs") public String max10secs() { //In some cases it can…
4
votes
1 answer

Spring boot: testing paged results using TestRestTemplate

I have a resource A that have a controller containing an endpoint for retrieving paged A items: public ResponseEntity getAllAs( @PageableDefault(size = 25, value = 0) Pageable pageable) { Page pagedAs = ..... return…
4
votes
0 answers

Best way for login different app on the server

I have 2 android app: ClientApp and CashierApp. It different app's but bouth app's can login on my server. I need implement login functional for this applications. On server side I have one controller - UserController and 2…
ip696
  • 6,574
  • 12
  • 65
  • 128
4
votes
2 answers

Consuming a RESTful Web Service: Controller Springboot error

i'm studying how to consume rest controller in spring, i'm using eclipse to run the java/spring , I want to ask i got error like this when running the java. i already tried to search about the caused,etc still dont find the solutions. anyone know…
4
votes
1 answer

Jackson also needs getter methods to correctly serialize a bean property using @JsonCreator

I am using Jackson to serialize some beans into JSON, inside an application that is using Spring Boot 1.5. I noticed that to serialize a bean using the @JsonCreator correctly, I have to declare the getter method for each property, plus the…
riccardo.cardin
  • 7,971
  • 5
  • 57
  • 106
4
votes
1 answer

How to generate RestController classes

I am writing Spring Boot application in intelliJ-IDEA, and have database with many tables on MySQL server. I generated Entity classes from database (Hibernate). Is there a way to generate Repository classes from Entity classes, and then to generate…
4
votes
1 answer

How to pass '/' character in the GET request?

I have an api : http://localhost:8080/mylocalserver/#/reports/{parameter1}/{parameter2} now the first parameter is parameter1 = "12345/EF" and the second parameter is parameter2 = "Text" I am using Spring Rest Controller for creating the api. When…
swetansh kumar
  • 475
  • 7
  • 17
4
votes
1 answer

Swagger Annotation to add a json example to the response class

How can I insert a default value instead of the "{}" using swagger annotations?
Chayma Atallah
  • 725
  • 2
  • 13
  • 30
4
votes
2 answers

Configure Multiple Database on Spring-Boot with JPA and Hibernate Web Application

I have ONE spring boot (1.5.4.RELEASE) project using java 8 deployed on AWS HPC. This project architect scope works for Spring Web Application(Website), Rest API Services(Mobile Developer) & Account Administration for Company. So there is 3…
user4856296
4
votes
1 answer

Control @RestController availability programmatically

Is it possible to control a @RestController programmatically to enable it or disable it? I don't want to just write code in each @RequestMapping method to do some kind of if (!enabled) { return 404Exception; } I've seen this question but that works…
Hilikus
  • 9,954
  • 14
  • 65
  • 118
4
votes
1 answer

Is it possible to get the RequestMethod-verb in a custom PreAuthorize method?

I'm using a custom access checker with @PreAuthorize: @RestController @RequestMapping("/users") public class Users { @PreAuthorize("@customAccessChecker.hasAccessToMethod('USERS', 'GET')") @RequestMapping(method = RequestMethod.GET) …
4
votes
2 answers

Spring MVC Controller Unit Testing : How do I set private instance boolean field?

I have a Spring MVC REST controller class that has a private instance boolean field injected via @Value , @Value("${...property_name..}") private boolean isFileIndex; Now to unit test this controller class, I need to inject this boolean. How do I…
Sabir Khan
  • 9,826
  • 7
  • 45
  • 98
4
votes
5 answers

Spring MVC @Controller to intercept own requests

Imagine we have a controller like this: @RestController @RequestMapping("/{parameter}") public class MyController { @ExceptionHandler(SomeException.class) public Object handleSomeException() { /* handle */ } …
scorpp
  • 635
  • 10
  • 16
4
votes
2 answers

Spring boot RestController won't work with classes which implements an interface

I'm trying to implement a Springboot REST api. and the class where I have defined the @RestController doesn't seem to be working. I have a class called MyService where it implements all the abstract methods. I have added the @RestController…
Madushika Perera
  • 402
  • 2
  • 5
  • 13