Questions tagged [spring-web]

The Spring Web model-view-controller (MVC) framework.

The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale, time zone and theme resolution as well as support for uploading files. The default handler is based on the @Controller and @RequestMapping annotations, offering a wide range of flexible handling methods. With the introduction of Spring 3.0, the @Controller mechanism also allows you to create RESTful Web sites and applications, through the @PathVariable annotation and other features.

Official Documentation

389 questions
72
votes
8 answers

Spring's @RequestParam with Enum

I have this enum : public enum SortEnum { asc, desc; } That I want to use as a parameter of a rest request : @RequestMapping(value = "/events", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public List
Antoine Martin
  • 1,587
  • 2
  • 12
  • 24
66
votes
8 answers

Overriding beans in Integration tests

For my Spring-Boot app I provide a RestTemplate though a @Configuration file so I can add sensible defaults(ex Timeouts). For my integration tests I would like to mock the RestTemplate as I dont want to connect to external services - I know what…
mvlupan
  • 2,786
  • 2
  • 19
  • 32
42
votes
7 answers

Spring RestTemplate and generic types ParameterizedTypeReference collections like List

An Abstract controller class requires List of objects from REST. While using Spring RestTemplate its not mapping it to required class instead it returns Linked HashMAp public List restFindAll() { RestTemplate restTemplate =…
vels4j
  • 10,808
  • 4
  • 35
  • 54
33
votes
5 answers

How to prevent spring-boot autoconfiguration for spring-web?

I'm using spring-boot and added spring-web dependency in maven pom, to make use of RestTemplate. Now spring tries to initialize an EmbeddedServletContext. How can I prevent it? Exception in thread "main"…
membersound
  • 66,525
  • 139
  • 452
  • 886
30
votes
4 answers

Spring Boot creating multiple (functioning) webmvc applications using auto configuration

Updated My question is how do I initialise an isolated spring webmvc web-app in spring boot. The isolated Web application should: Should not initialise itself in the application class. We want to do these in a starter pom via auto configuration.…
Hassan Syed
  • 19,054
  • 9
  • 76
  • 156
29
votes
5 answers

Can I use @Requestparam annotation for a Post request?

I have this controller method: @PostMapping( value = "/createleave", params = {"start","end","hours","username"}) public void createLeave(@RequestParam(value = "start") String start, @RequestParam(value =…
Maurice
  • 4,056
  • 5
  • 30
  • 66
26
votes
5 answers

Prototype Bean doesn't get autowired as expected

TestController.java @RestController public class TestController { @Autowired private TestClass testClass; @RequestMapping(value = "/test", method = RequestMethod.GET) public void testThread(HttpServletResponse response) throws…
Kim
  • 3,985
  • 4
  • 29
  • 53
21
votes
4 answers

Proper way of streaming using ResponseEntity and making sure the InputStream gets closed

One of our application leaks file handles and we have not yet found the cause for this. In the code I can see several functions similar to this: public ResponseEntity getFoo( ... ) { InputStream content = getContent(...) …
Marged
  • 9,123
  • 9
  • 45
  • 87
21
votes
4 answers

Spring RestTemplate POST Request with URL encoded data

I'm new to Spring and trying to do a rest request with RestTemplate. The Java code should do the same as below curl command: curl --data "name=feature&color=#5843AD" --header "PRIVATE-TOKEN: xyz"…
Tobi
  • 251
  • 1
  • 2
  • 8
18
votes
4 answers

HttpMediaTypeNotAcceptableException for errors with text/plain message response?

I have a simple webservice that returns content either as json or as plain text (depending on the clients' accept http header). Problem: if an error occurs during text/plain request, Spring somehow returns a 406 Not Acceptable. Which is kind of…
membersound
  • 66,525
  • 139
  • 452
  • 886
18
votes
6 answers

How to print to console in Spring Boot Web Application

Coming from a Node background, what is the equivalent of console.log() in spring boot? For example I'd like to see in my console the job info in the following method. @RequestMapping(value = "jobposts/create", method = RequestMethod.POST) public Job…
SpaceOso
  • 255
  • 1
  • 2
  • 13
16
votes
3 answers

Spring REST Controller returns JSON with empty data

I have a simple Spring Boot web application. I'm trying to receive some data from server. The Controller returns a collection, but the browser receives empty JSON - the number of curly brackets is equals to the number of objects from server, but its…
Radziasss
  • 183
  • 1
  • 1
  • 10
16
votes
2 answers

How to test DeferredResult timeoutResult

I'm implementing long polling as per the Spring blog from some time ago. Here my converted method with same response signature as before, but instead of responding immediately, it now uses long polling: private Map
Tim
  • 18,795
  • 8
  • 63
  • 90
14
votes
2 answers

how to build console command in spring boot web application using spring shell?

I have created restfull web application using spring boot web starter which works well. I am able to access it through urls. But I have requirement to create console command which can compute and store some values at the backend. I want to be able…
vishal
  • 3,643
  • 11
  • 51
  • 96
12
votes
3 answers

Spring tries to deserialize to LinkedHashMap instead of POJO

I'm creating a simple rest controller with Spring Boot and the Web dependency. I'm trying to deserialize a JSON body to a test POJO with only 3 fields, but when I attempt to make a POST request, the server responds with a 500 error and the error I…
mac
  • 123
  • 1
  • 6
1
2 3
25 26