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
16
votes
2 answers

Spring MVC thymeleaf random crash

I have wierd issue with Spring MVC and thymeleaf. When I run my web application I get random crash from time to time. Sometimes all works just fine but sometimes I get something like that: javax.servlet.ServletException: Servlet.init() for servlet…
Sayaki
  • 769
  • 14
  • 36
16
votes
6 answers

#oauth2 security expressions on method level

What should I do to be able to use #oauth2 security expressions on method level like on the example below? @RequestMapping(value = "email", method = RequestMethod.GET) @ResponseBody @PreAuthorize("#oauth2.hasScope('read')") public String…
Marek Raki
  • 3,056
  • 3
  • 27
  • 50
16
votes
4 answers

Spring security 4 custom login j_spring_security_check return http 302

I asked a question about latest spring framework, code based configuration here initializer public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Class[]…
Timeless
  • 7,338
  • 9
  • 60
  • 94
16
votes
5 answers

Convert a object into JSON in REST service by Spring MVC

I'm trying to create a REST service using Spring MVC and it's working if I'm returning a plain string. My requirement is to return a JSON string of the Java object. Don't know how to achieve this by implicit conversion. Here is my…
Roul
  • 945
  • 1
  • 12
  • 34
16
votes
1 answer

Why I must have a default constructor in a Spring configuration class annoted by the @Configuration annotation?

I am studying for Spring Core certification and, on the provided study stuff, I have this question but I can't give an answer to it. Why must you have to have a default constructor in your @Configuration annotated class? I don't declare any…
Java Surfer
  • 613
  • 3
  • 9
  • 13
16
votes
3 answers

How to make @PreAuthorize having higher precedence than @Valid or @Validated

I am using spring boot, and I have enabled the global method security in WebSecurityConfigurerAdapter by @EnableGlobalMethodSecurity(prePostEnabled = true, order = Ordered.HIGHEST_PRECEDENCE) And Below is my controller…
16
votes
1 answer

Where can I find the example applicationContext.xml file

With Spring 3 distribution there was a project folder which was packaged in the distribution . This project folder had sample applicationContext.xml file which can be used . However when I have downloaded Spring 4 distribution from here it does not…
Anshul
  • 267
  • 1
  • 4
  • 13
16
votes
5 answers

Spring boot MVC: can't find JSP

Problem: I can't reach my view under WEB-INF/jsp on my Spring Boot web MVC app. What I've done: this is my JSP: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ taglib prefix="spring"…
abierto
  • 1,447
  • 7
  • 29
  • 57
16
votes
5 answers

NoSuchMethodError: org.springframework.beans.factory.xml.XmlReaderContext.getEnvironment()Lorg/springframework/core/env/Environment; With zkoss

I am facing following error, java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.XmlReaderContext.getEnvironment()Lorg/springframework/core/env/Environment; at…
Bilbo Baggins
  • 2,899
  • 10
  • 52
  • 77
16
votes
1 answer

Spring OAuth 2: public access to a resource

How do I allow public access in an specific URL in a Spring Security OAuth-2 Rest application. I have all URLs started with /rest/** secured, but would like to make /rest/about public, so I would not require the user to authenticate to access it. I…
Fabricio Lemos
  • 2,905
  • 2
  • 31
  • 31
16
votes
2 answers

Spring MVC @ModelAttribute method

Question about Spring MVC @ModelAttribute methods, Setting model attributes in a controller @RequestMapping method verses setting attribute individually with @ModelAttribute methods, which one is considered better and is more used? From design point…
Kamal Kishore
  • 193
  • 1
  • 1
  • 8
16
votes
4 answers

Spring Bean Validation @Valid handling

I have created a Spring MVC REST service using Bean Validation 1.2 with the following method: @RequestMapping(value = "/valid") public String validatedMethod(@Valid ValidObject object) { } If object isn't valid, Tomcat informs me that The request…
Dormouse
  • 1,617
  • 1
  • 23
  • 33
16
votes
3 answers

How to configure MappingJackson2HttpMessageConverter registered by spring-hateoas

I like to use spring-hateoas in my project and configured it with @EnableHypermediaSupport. The problem now is, that this magic config annotation registers its own MappingJackson2HttpMessageConverter and my own customized converter will be…
André Menneken
  • 193
  • 1
  • 7
16
votes
5 answers

Spring :Inserting cookies in a REST call response

I am implementing REST API endpoints using spring mvc. I am trying to send back a HTTP response with a cookie value. This is the equivalent of what I need to do in ruby SINATRA : response.set_cookie('heroku-nav-data', :value =>…
user3242743
  • 1,751
  • 5
  • 22
  • 32
16
votes
2 answers

How to set content-length in Spring MVC REST for JSON?

I have some code: @RequestMapping(value = "/products/get", method = RequestMethod.GET) public @ResponseBody List getProducts(@RequestParam(required = true, value = "category_id") Long categoryId) { // some code here return new…
ruslanys
  • 1,183
  • 2
  • 13
  • 25