Questions tagged [spring-mvc]

A framework for building Java web applications based on the Model-View-Controller (MVC) pattern. It promotes flexible and decoupled code from the underlying view technologies.

Spring MVC is an action-based (as opposed to component-based) web framework built on top of the Spring IOC Container. MVC stands for Model View Controller, a long standing design pattern that layers an application separating presentation concerns from business logic see Portland Pattern Repository's MVC Entry

The latest stable version is 5.1.4 and was released in January 2019, and the current docs can be found in the MVC section of the Spring Reference.

Spring Version 5.0 fully supports Java 9 features, this release now requires Java SE 8.

Major Spring Releases

  • First Release : Year 2004
  • Spring 2.0 : Intoduced namespaces and support.
  • Spring 2.5 : Anotation Based Configuration
  • Spring 3.0 : Strong Java 5+ foundation across framework, Introduced @Configuration model
  • Spring 3.2 : Java Based Configuration introduced
  • Spring 4.0 : Java 8 Support, removed Deprecated classes.
  • Spring 5.0 : Java 9 Support, reactive programming support

The Spring Framework comprises several modules that provide a range of services:

  • Inversion of Control container: configuration of application components and lifecycle management of objects, done mainly via dependency injection
  • Aspect-oriented programming: enables implementation of cross-cutting routines
  • Data access: working with relational database management systems on the platform using and object-relational mapping tools and with databases
  • Transaction management: unifies several transaction management APIs and coordinates transactions for Java objects
  • Model-view-controller: an HTTP- and servlet-based framework providing hooks for extension and customization for web applications and RESTfull web services.
  • Remote Access framework: configurative RPC-style export and import of Java objects over networks supporting , and HTTP-based protocols including web services ()
  • Convention-over-configuration: a rapid application development solution for Spring-based enterprise applications is offered in the module
  • Batch processing: a framework for high-volume processing featuring reusable functions including logging/tracing, transaction management, job processing statistics, job restart, skip, and resource management
  • Authentication and authorization: configurable security processes that support a range of standards, protocols, tools and practices via the Spring Security sub-project (formerly - Acegi Security System for ).
  • Remote Management: configurative exposure and management of Java objects for local or remote configuration via .
  • Messaging: configurative registration of message listener objects for transparent message-consumption from message queues via , improvement of message sending over - - standard APIs
  • Testing: support classes for writing unit tests and integration tests
58288 questions
15
votes
1 answer

How does Spring get the result from an endpoint that returns CompletableFuture object?

In the code below, when the endpoint getPerson gets hit, the response will be a JSON of type Person. How does Spring convert CompletableFuture to Person? @RestController public class PersonController { @Autowired private…
MA1
  • 926
  • 10
  • 28
15
votes
9 answers

How to use findAll() on CrudRepository returning a List instead of Iterable

I want to write a FindAll() method which returns a List of all Student objects. But the CRUDRepository only has Iterable<> findAll(). The goal is to get all students in a List and pass it to the API Controller so I can get all the students with a…
Bram
  • 669
  • 3
  • 12
  • 25
15
votes
4 answers

Performance - Spring Boot - Server Response Time

I have a strange behaviour on our spring boot application: Frontend/Client - angular 6 Backend - spring boot - spring MVC - embedded tomcat - Linux After restarting the backend the first calls to a controller needs about 5 seconds, the following…
tomas
  • 830
  • 3
  • 8
  • 25
15
votes
3 answers

Reading httprequest content from spring exception handler

I Am using Spring's @ExceptionHandler annotation to catch exceptions in my controllers. Some requests hold POST data as plain XML string written to the request body, I want to read that data in order to log the exception. The problem is that when i…
Noam Nevo
  • 3,021
  • 10
  • 35
  • 49
15
votes
2 answers

How to stream binary data in a response body in Spring WebFlux

I am making a project using Spring WebFlux. In the past I had used StreamingResponseBody for streaming responses back to the client, but I can't find the equivalent in WebFlux. Example: import…
ESala
  • 6,878
  • 4
  • 34
  • 55
15
votes
5 answers

Spring boot after https: The Tomcat connector configured to listen on port 8444 failed to start.

I followed a guide to enable https in Spring Boot. The application was beforehand working on https://localhost:8080 I've created a keystore.jks which is in the same directory as my application.properties, which now looks like: # Define a custom port…
cbll
  • 6,499
  • 26
  • 74
  • 117
15
votes
1 answer

Spring controller: Content-Type for StreamingResponseBody

In search for the least amount of code to serve a BufferedImage (painted in a service-class) from a spring-mvc Controller, I came up with the following: @GetMapping(value = "/image", produces = "image/png") public StreamingResponseBody image() { …
Rüdiger Schulz
  • 2,588
  • 3
  • 27
  • 43
15
votes
2 answers

Spring security application of antMatcher() vs. antMatchers()

Just want to see whether I'm interpreting the answer to this question the right way. If we only need to secure one path like this: http.antMatcher("/api/**").authorizeRequests().... Then use antMatcher(). If we need to secure multiple URL paths…
Ole
  • 41,793
  • 59
  • 191
  • 359
15
votes
3 answers

Spring Security - multiple configurations - add LogoutHandler

I have a spring-boot application using spring-security. The security configuration is split into multiple instances of WebSecurityConfigurerAdapter. I have one where I configure logout in general: @Override protected void configure(HttpSecurity…
Rüdiger Schulz
  • 2,588
  • 3
  • 27
  • 43
15
votes
4 answers

Custom converter for @RequestParam in Spring MVC

I am getting an encrypted String as Query parameter to a Spring rest controller method. I wanted to decrypt the string before it reaches the method based on some annotation (say @Decrypt) like below @RequestMapping(value = "/customer", method =…
Prabhakar D
  • 1,084
  • 2
  • 15
  • 35
15
votes
1 answer

Weird problem when binding a dynamic list

INITIAL QUESTION (UPDATED BELOW) I'm using an AutoPopulatingList list to instatiate an object invoking a constructor with some parameters. Something like the code below. I had used it before without any problems but I can't get it working…
Javi
  • 19,387
  • 30
  • 102
  • 135
15
votes
5 answers

What are the best practices around setting global model attributes in Spring MVC?

I have a menu that is data driven(cached) and it is a global component. I want to be able to inject the menu items for every request since every page is going to be using it. What is the best place to put it? I'm using annotation based Spring3. Best…
Art
  • 5,864
  • 3
  • 30
  • 32
15
votes
3 answers

How to globally configure `@DateTimeFormat` pattern in Spring Boot?

Im my Spring Boot application, I have some controllers that accept a date as query parameter: @RestController public class MyController { @GetMapping public ResponseEntity getDataByDate( @RequestParam(value = "date")…
britter
  • 1,352
  • 1
  • 11
  • 26
15
votes
4 answers

Custom Error message with @Preauthorize and @@ControllerAdvice

We are using spring and spring-security-3.2. Recently We are adding annotations @PreAuthorize to RestAPIs(earlier it was URL based). @PreAuthorize("hasPermission('salesorder','ViewSalesOrder')") @RequestMapping(value =…
Harsh
  • 151
  • 1
  • 5
15
votes
3 answers

Transactional: controller vs service

Consider I have a controller method get() which calls a few service methods working with database. Is it correct to make the entire controller method transactional or just every service method? It seems to me that we must make get() transactional…
Andrey Minogin
  • 4,521
  • 6
  • 38
  • 60