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
15
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,993
  • 14
  • 59
  • 102
13
votes
4 answers

Converting Lazy Loaded object to JSON in spring boot jpa

I am getting error while sending the Lazy loaded object as a JSON in response to REST request in spring boot. When I request from browser to fetch the parentTree and call get method to get the version to test the lazy loading and return version but…
Developer
  • 493
  • 2
  • 8
  • 19
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
11
votes
2 answers

Async Spring Controllers vs normal Controllers

I wanted to analyze the improvement I may see by enabling Async Controllers in Spring Boot over normal controller So here is my test code. One API returns a Callable and another is normal controller API. Both APIs block for 10secs simulating a long…
hellojava
  • 4,904
  • 9
  • 30
  • 38
11
votes
3 answers

How to map JSON fields to custom object properties?

I have a simple json message with some fields, and want to map it to a java object using spring-web. Problem: my target classes fields are named differently than int he json response. How can I anyhow map them to the object without having to rename…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
10
votes
3 answers

Spring form submission with minum boilerplate

I've been trying to figure out what the best practice is for form submission with spring and what the minimum boilerplate is to achieve that. I think of the following as best practise traits Validation enabled and form values preserved on…
Johan Sjöberg
  • 47,929
  • 21
  • 130
  • 148
10
votes
3 answers

Null @AuthenticationPrincipal with Spring-Boot / Security

I setup my Spring Security application according to the reference document and after hours of troubleshooting I continue to get a null @AuthenticationPrincipal passed into my controller. The authentication mechanism is working fine against the…
szxnyc
  • 2,495
  • 5
  • 35
  • 46
9
votes
1 answer

SmartValidator - manually calling validate with groups

Spring 4.3.2 I need to call SmartValidator.validate() manually and I need it utilize the validation groups that I have defined on the target entity. The javadoc says this... "This variant of validate() supports validation hints, such as …
Jim Ott
  • 725
  • 13
  • 24
9
votes
2 answers

Spring Web MVC: no request body possible for HTTP DELETE anymore

I have a question for the developers of Spring Web MVC. In a nutshell: previously it was possible to send a request body in an HTTP DELETE message, but now it is not possible anymore. Why? In detail: We are using…
Johannes Flügel
  • 3,112
  • 3
  • 17
  • 32
8
votes
2 answers

How to configure direct field access on @Valid in Spring?

How can I tell spring-web to validate my dto without having to use getter/setter? @PostMapping(path = "/test") public void test(@Valid @RequestBody WebDTO dto) { } public class WebDTO { @Valid //triggers nested validation private…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
8
votes
2 answers

Spring ResponseEntity for optionals

A construct that I often use in my code is the following: @RestController public class HelloController { @Autowired private HelloService helloService; @GetMapping("/hello") ResponseEntity getHelloMessage() { Optional
Rob Faber
  • 81
  • 1
  • 6
8
votes
1 answer

Spring Rest Controller: how to selectively switch off validation

In my controller I have a method for creating an entity import javax.validation.Valid; ... @RestController public class Controller { @RequestMapping(method = RequestMethod.POST) public ResponseEntity create(@Valid @RequestBody RequestDTO…
Johannes Flügel
  • 3,112
  • 3
  • 17
  • 32
8
votes
4 answers

Download or redirect with error message to another controller action in Spring web MVC

Idea: I have a Spring web MVC action that should accomplish one or both of these taks: Download a file from a remote server and write the input stream to the response output stream Or catch the exception of the download, set one of multiple error…
swaechter
  • 1,357
  • 3
  • 22
  • 46
8
votes
2 answers

Spring CORS controller annotation not working

I want to allow cross origin requests for one domain. My project uses Spring so I want to take advantage of the new CORS support. I am using version 4.2.0 for all springframework dependencies. I followed the example here…
ilinca
  • 1,343
  • 15
  • 17
7
votes
2 answers

How to log spring-webflux WebClient request + response details (bodies, headers, elasped_time)?

Basically, I want to log a request/response informations in one log containing bodies/headers with a Spring WebClient. With Spring RestTemplate we can do it with a ClientHttpRequestInterceptor. I find about ExchangeFilterFunction for Spring…
1
2
3
25 26