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
216
votes
26 answers

Spring Boot not serving static content

I can't get my Spring-boot project to serve static content. I've placed a folder named static under src/main/resources. Inside it I have a folder named images. When I package the app and run it, it can't find the images I have put on that…
Vinicius Carvalho
  • 3,994
  • 4
  • 23
  • 29
206
votes
6 answers

How do I retrieve query parameters in a Spring Boot controller?

I am developing a project using Spring Boot. I've a controller which accepts GET requests. Currently I'm accepting requests to the following kind of URLs: http://localhost:8888/user/data/002 but I want to accept requests using query…
Mehandi Hassan
  • 2,381
  • 4
  • 16
  • 20
205
votes
5 answers

What is the difference between ApplicationContext and WebApplicationContext in Spring MVC?

What is the difference between Application Context and Web Application Context? I am aware that WebApplicationContext is used for Spring MVC architecture oriented applications? I want to know what is the use of ApplicationContext in MVC…
Sumit Trehan
  • 3,985
  • 3
  • 27
  • 42
203
votes
23 answers

How to handle static content in Spring MVC?

I am developing a webapp using Spring MVC 3 and have the DispatcherServlet catching all requests to '/' like so (web.xml): app
hamo
  • 2,337
  • 3
  • 15
  • 13
198
votes
4 answers

Difference between JAX-RS and Spring Rest

I confused with the difference between JAX-RS (well, maybe should use Jersey to do comparison since JAX-RS is just spec) and Spring for Restful services. I tried to search for more information online and it become more confusing. My company is using…
hades
  • 4,294
  • 9
  • 46
  • 71
193
votes
17 answers

How to fix Hibernate LazyInitializationException: failed to lazily initialize a collection of roles, could not initialize proxy - no Session

In the custom AuthenticationProvider from my spring project, I am trying read the list of authorities of the logged user, but I am facing the following error: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of…
Kleber Mota
  • 8,521
  • 31
  • 94
  • 188
190
votes
11 answers

What is username and password when starting Spring Boot with Tomcat?

When I deploy my Spring application via Spring Boot and access localhost:8080 I have to authenticate, but what is the username and password or how can I set it? I tried to add this to my tomcat-users file but it didn't work:
Gustavo
  • 3,461
  • 7
  • 26
  • 41
188
votes
20 answers

How to set base url for rest in spring boot?

I'm trying to to mix mvc and rest in a single spring boot project. I want to set base path for all rest controllers (eg. example.com/api) in a single place (I don't want annotate each controller with @RequestMapping('api/products'), instead, just…
Teimuraz
  • 8,795
  • 5
  • 35
  • 62
184
votes
56 answers

This application has no explicit mapping for /error

I used maven to do the tutorial https://spring.io/guides/gs/uploading-files/ All the codes I used was copied. The Application can run, but I get the error: Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing…
Deng Steve
  • 1,851
  • 2
  • 11
  • 5
184
votes
4 answers

How to get access to HTTP header information in Spring MVC REST controller?

I am new to web programming in general, especially in Java, so I just learned what a header and body is. I'm writing RESTful services using Spring MVC. I am able to create simple services with the @RequestMapping in my controllers. I need help…
Horse Voice
  • 8,138
  • 15
  • 69
  • 120
181
votes
4 answers

Difference between Interceptor and Filter in Spring MVC

I'm a little bit confused about Filter and Interceptor purposes. As I understood from docs, Interceptor is run between requests. On the other hand Filter is run before rendering view, but after Controller rendered response. So where is the…
rpieniazek
  • 2,160
  • 2
  • 12
  • 16
177
votes
6 answers

Difference between @Valid and @Validated in Spring

Spring supports two different validation methods: Spring validation and JSR-303 bean validation. Both can be used by defining a Spring validator that delegates to other delegators including the bean validator. So far so good. But when annotating…
Sergei Tachenov
  • 24,345
  • 8
  • 57
  • 73
176
votes
10 answers

Redirect to an external URL from controller action in Spring MVC

I have noticed the following code is redirecting the User to a URL inside the project, @RequestMapping(method = RequestMethod.POST) public String processForm(HttpServletRequest request, LoginForm loginForm, BindingResult…
Jake
  • 25,479
  • 31
  • 107
  • 168
175
votes
9 answers

How to get active user's UserDetails

In my controllers, when I need the active (logged in) user, I am doing the following to get my UserDetails implementation: User activeUser =…
The Awnry Bear
  • 4,599
  • 3
  • 29
  • 33
175
votes
12 answers

Spring MVC - How to return simple String as JSON in Rest Controller

My question is essentially a follow-up to this question. @RestController public class TestController { @RequestMapping("/getString") public String getString() { return "Hello World"; } } In the above, Spring would add "Hello…
The Gilbert Arenas Dagger
  • 12,071
  • 13
  • 66
  • 80