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

386 questions
124
votes
11 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
  • 3,536
  • 3
  • 22
  • 35
95
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,903
  • 2
  • 16
  • 28
55
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
  • 11,208
  • 5
  • 38
  • 63
45
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
  • 491
  • 1
  • 4
  • 8
38
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
  • 6,698
  • 9
  • 47
  • 104
34
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
  • 81,582
  • 193
  • 585
  • 1,120
30
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
  • 10,577
  • 10
  • 57
  • 99
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
  • 20,075
  • 11
  • 87
  • 171
27
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
  • 5,045
  • 6
  • 38
  • 60
26
votes
8 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
  • 358
  • 1
  • 3
  • 15
21
votes
6 answers

package org.springframework.web.bind.annotation does not exist even though it's defined in POM

So I have this code import org.springframework.web.bind.annotation.GetMapping; And I already have the following in my POM file war 4.3.0.RELEASE
MassiveParty24
  • 211
  • 1
  • 2
  • 3
20
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
  • 81,582
  • 193
  • 585
  • 1,120
18
votes
4 answers

Content type 'text/plain;charset=UTF-8' not supported error in spring boot inside RestController class

I got the following @RestController inside a spring boot application : @Data @RestController public class Hello { @Autowired private ResturantExpensesRepo repo; @RequestMapping(value = "/expenses/restaurants",method =…
nadavgam
  • 2,014
  • 5
  • 20
  • 48
17
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
  • 193
  • 1
  • 1
  • 11
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
  • 19,793
  • 8
  • 70
  • 95
1
2 3
25 26