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
5 answers

Spring Rest Controller track entity view count

I need to track entity view count.. for example I have a Product entity and have the following API endpoint: GET /products/{productID} In case I want to track a view count of a particular Product should I add additional logic that will increment…
alexanoid
  • 24,051
  • 54
  • 210
  • 410
3
votes
1 answer

Spring @RequestBody REST services post method return 415 in some entity relation

I am working with spring rest and hibernate. I checked stackoverflow these linkes but they did not solve my issue! Spring MVC 3.1 REST services post method return 415 415 Unsupported MediaType for POST request in spring application HTTP Status 415…
3
votes
0 answers

use exceptionMapper for restcontroller so that jersey and restcontroller can coexist

I was using spring boot with Jersey 1. Used ExceptionMapper to handle the exceptions globally. Now we are planning to migrate to spring MVC for restful purpose. So, changing few of the endpoints to use dispatcher servlet. Is there any way to handle…
Ajay
  • 4,134
  • 3
  • 20
  • 19
3
votes
2 answers

Spring Boot - How can I pass custom values in HTTP Post api?

I'm new with Spring Boot and I have difficult to understand how can I pass data. For example: I want pass those data to my server: { "code", 1, "name": "C01" } So I have create always a custom Object with code and name as attributes to have…
Nammen8
  • 619
  • 1
  • 11
  • 31
3
votes
1 answer

Spring @RestController not setting cookies with response

I have the following rest endpoint that I would like to send a cookie along with my ResponseEntity. However after succesfully sending the response, the cookie is nowhere to be found. @RequestMapping(value = "myPath", method =…
secondbreakfast
  • 4,194
  • 5
  • 47
  • 101
3
votes
1 answer

Securing spring mvc REST api using siteminder

I have written REST web service in java using spring MVC. As this service is stateless, how I can secure it using siteminder? For login authentication, we are using siteminder at frontend.
jinal
  • 71
  • 1
  • 7
3
votes
0 answers

Spring CORS headers not added on 404

I'm setting up CORS in spring with: @Bean public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurerAdapter() { @Override public void addCorsMappings(CorsRegistry registry) { …
3
votes
1 answer

How to call another api from same app in spring boot

I have two RestControllers for user and Company. CompanyController: fetch from and store company information to companies table using service and repo level. UsersController : It is used to fetch and store users. Relationship: Each user is…
Sachin
  • 333
  • 1
  • 4
  • 19
3
votes
2 answers

No converter found for return value of type: class org.json.JSONArray

I want to return a JSONArray(org.json.jar) object from spring controller method, this is my java spring controller : import org.json.JSONArray; import org.json.JSONException; @RestController public class…
Naveen
  • 773
  • 3
  • 17
  • 40
3
votes
3 answers

Spring Boot RestController not returning JSON data

I have an SSCCE that reproduces this problem exactly at my GitHub repo here. To run it locally just: Clone it ./gradlew clean build java -Dspring.config=. -jar build/libs/bootup.jar Open a browser to http://localhost:9200/cars/1 Essentially I…
smeeb
  • 27,777
  • 57
  • 250
  • 447
3
votes
0 answers

include Spring Boot Rest Api Jar file into Another Spring project

I have Spring boot Rest api , which works fine @RequestMapping("/api/get") public PomData getPomData( ) throws IOException { PomData pd=new PomData(); pd.setName("name"); pd.setVersion("version"); return pd; } I want to call this…
3
votes
1 answer

How to log the incoming json request in spring restful webservice with restcontroller?

I want to log all the incoming requests which will be in json format.I am using spring @RestController and @RequestBody annotations to bind the incoming json content to java objects.But i want to log these requests to logger files.I have searched…
sai
  • 109
  • 2
  • 13
3
votes
1 answer

Spring mvc - Configuring Error handling for XML and JSON Response

i have one REST API method :which will return Xml as response . Just for simplicity assume it throws simple Exception. @RequestMapping(value = "machine/xmlData", method = RequestMethod.GET, produces = "application/xml") public…
lesnar
  • 2,400
  • 7
  • 41
  • 72
3
votes
1 answer

How to correctly implement a REST service that returns a list of images using Spring MVC\Boot?

I am not so into RESTful web services and I have the following doubt about how correctly return a list of image using RESTful paradigm. I am working on a Spring Batch application (but it is the same thing that uses Spring MVC for this purpose). I…
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
3
votes
2 answers

Spring boot cannot access @Value inside ClientHttpRequestInterceptor

I am using spring-boot-1.3.3.I want to intercept Rest template and i am able to intercept it but i am unable to access the application.properties.It always returns null. package com.sample.filter; import…