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
17
votes
3 answers

How to bind a string array of properties in Spring?

I have the following in my application.properties file some.server.url[0]=http://url some.server.url[1]=http://otherUrl How do I refer to the array of properties using the @Value anotation inside a @Bean method? I am using Java 6 with Tomcat 7 and…
SebS
  • 571
  • 3
  • 6
  • 16
17
votes
1 answer

Spring Cancel @Async Task

I want to be able to cancel a method marked with the @Async annotation by it's future. I have a Spring method marked with the @Async annotation. This method does some computation, and eventually returns a result. All examples I have seen recommend…
Patrick D
  • 6,659
  • 3
  • 43
  • 55
17
votes
1 answer

Jackson xml ignore empty Objects when serializing

I want to create a xml from a html form with the help of a Spring MVC ModelAttribute (Person) and Jackson. form: ....
chrisishere
  • 183
  • 1
  • 1
  • 4
17
votes
4 answers

Setting up MockMvc with @WebMvcTest in Spring Boot 1.4 MVC Testing

I have few working code to set up MockMVc in different ways with the new Spring Boot 1.4 @WebMvcTest. I understand the standaloneSetup approach. What I want to know is the difference between setting up MockMvc through WebApplicationContext and by…
user2693135
  • 1,206
  • 5
  • 21
  • 44
17
votes
1 answer

properties not accessible to the child (web) context

A typical use-case: I'm having applicationContext.xml and dispatcher-servlet.xml. In the parent context (applicationContext.xml) I have: However, the properties loaded by…
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
17
votes
2 answers

Enable CORS for OPTIONS request using Spring Framework

Every time I make a PUT Ajax call to my service, it return the following error: XMLHttpRequest cannot load http://localhost:8080/users/edit. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is…
daniegarcia254
  • 1,157
  • 4
  • 17
  • 36
17
votes
2 answers

Can not set field to com.sun.proxy.$Proxy

For file upload I am trying to inject and use a Validator in my Spring Controller like this: @RestController @RequestMapping("/api") public class FileController{ @Autowired private MessageSource messageSource; @Autowired …
FunnyJava
  • 446
  • 1
  • 6
  • 17
17
votes
2 answers

How to gracefully handle exceptions in Spring Security not handled by ControllerAdvice?

I have recently implemented Spring Security in my Spring 4 / Hibernate Web application to handle logging in/out and different user roles. After a lot of reading it appears to work pretty fine now, but I noticed that exceptions thrown due to a wrong…
klausch
  • 612
  • 2
  • 10
  • 22
17
votes
3 answers

SpringBoot When file upload size limit exceeds getting MultipartException instead of MaxUploadSizeExceededException

I have simple SpringBoot app file uploading functionality where max file upload file size is 2 MB. I have configured multipart.max-file-size=2MB it is working fine. But when I try to upload files with larger than 2 MB size I want to handle that…
K. Siva Prasad Reddy
  • 11,786
  • 12
  • 68
  • 95
17
votes
3 answers

Getting httpServletRequest attribute with MockMvc

I have a really simple controller defined in this way: @RequestMapping(value = "/api/test", method = RequestMethod.GET, produces = "application/json") public @ResponseBody Object getObject(HttpServletRequest req, HttpServletResponse res) { …
Andrea Girardi
  • 4,337
  • 13
  • 69
  • 98
17
votes
10 answers

How to display current logged-in user's information in all templates including view managed by WebMvcConfigurerAdapter in Spring Security application

I have a Spring Boot application that uses Spring Security and Thymeleaf template. I am trying to display the logged-in user's first name and last name in a template when the controller is managed by a subclass of WebConfigurerAdapter. So, say my…
Dee
  • 573
  • 1
  • 4
  • 10
17
votes
1 answer

bind Spring HandlerInterceptor only to one controller

Using Spring 3.0.2.RELEASE. I'm having 2 Controllers in package com.myCompany. The Controllers are activated via Component-scan then I'm having a interceptor bind to the 2 controllers via…
Martin Dürrmeier
  • 1,653
  • 5
  • 18
  • 35
17
votes
2 answers

Annotation based ServiceLocatorFactoryBean?

I would like to implement Factory pattern in my project..i have gone through online resources and I came to know that spring ServiceLocatorFactoryBean should be implemented instead of normal java factory pattern.... i have followed this link but it…
kumar
  • 481
  • 3
  • 7
  • 18
17
votes
7 answers

How to dynamically add Entity in Hibernate?

I'm a java developer. I'm using spring 4.0.1 and hibernate 4.2.21. I have a class as follow: @Entity @Inheritance(...) public abstract class Feature{ @Id @GeneratedValue protected Long id; ... } Now I have some many class as follow: …
Morteza Malvandi
  • 1,656
  • 7
  • 30
  • 73
17
votes
2 answers

spring combine two validation annotations in one

I'm using Spring+Hibernate+Spring-MVC. I want to define a custom constraint combining two other predefined validation annotations: @NotNull @Size like this: import javax.validation.constraints.NotNull; import…
Dariush Jafari
  • 5,223
  • 7
  • 42
  • 71