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

When using Spring Security, what is the proper way to obtain current username (i.e. SecurityContext) information in a bean?

I have a Spring MVC web app which uses Spring Security. I want to know the username of the currently logged in user. I'm using the code snippet given below . Is this the accepted way? I don't like having a call to a static method inside this…
Scott Bale
  • 10,649
  • 5
  • 33
  • 36
300
votes
7 answers

How to use multiple @RequestMapping annotations in spring?

Is it possible to use multiple @RequestMapping annotations over a method? Like : @RequestMapping("/") @RequestMapping("") @RequestMapping("/welcome") public String welcomeHandler(){ return "welcome"; }
wuntee
  • 12,170
  • 26
  • 77
  • 106
290
votes
4 answers

What exactly is Field Injection and how to avoid it?

I read in some posts about Spring MVC and Portlets that field injection is not recommended. As I understand it, field injection is when you inject a Bean with @Autowired like this: @Component public class MyComponent { @Autowired private…
T. Jung
  • 3,327
  • 3
  • 11
  • 19
279
votes
11 answers

Difference between Spring MVC and Spring Boot

I have just started learning Spring. In my next step, I would like to develop bigger web applications. Now I am wondering if I should start with Spring Boot or Spring MVC. I have already read some stuff, but it is confusing because both look…
Gero
  • 12,993
  • 25
  • 65
  • 106
273
votes
23 answers

Spring - No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call

I get this error when trying to invoke "persist" method to save entity model to database in my Spring MVC web application. Can't really find any post or page in internet that can relate to this particular error. It seems like something's wrong with…
Michał Bil
  • 3,179
  • 5
  • 20
  • 24
272
votes
4 answers

RESTful Authentication via Spring

Problem: We have a Spring MVC-based RESTful API which contains sensitive information. The API should be secured, however sending the user's credentials (user/pass combo) with each request is not desirable. Per REST guidelines (and internal business…
Chris Cashwell
  • 22,308
  • 13
  • 63
  • 94
266
votes
7 answers

Spring MVC: Complex object as GET @RequestParam

Suppose i have a page that lists the objects on a table and i need to put a form to filter the table. The filter is sent as an Ajax GET to an URL like that: http://foo.com/system/controller/action?page=1&prop1=x&prop2=y&prop3=z And instead of having…
renanleandrof
  • 6,699
  • 9
  • 45
  • 67
252
votes
33 answers

Spring boot - Not a managed type

I use Spring boot+JPA and having a problem while starting the service. Caused by: java.lang.IllegalArgumentException: Not an managed type: class com.nervytech.dialer.domain.PhoneSettings at…
user1578872
  • 7,808
  • 29
  • 108
  • 206
230
votes
14 answers

Trigger 404 in Spring-MVC controller?

How do I get a Spring 3.0 controller to trigger a 404? I have a controller with @RequestMapping(value = "/**", method = RequestMethod.GET) and for some URLs accessing the controller, I want the container to come up with a 404.
NA.
  • 6,451
  • 9
  • 36
  • 36
228
votes
4 answers

@RequestParam in Spring MVC handling optional parameters

Is it possible for a Spring controller to handle both kind of requests? 1) http://localhost:8080/submit/id/ID123432?logout=true 2) http://localhost:8080/submit/id/ID123432?name=sam&password=543432 If I define a single controller of the kind: …
luksmir
  • 3,104
  • 5
  • 22
  • 38
227
votes
22 answers

Add context path to Spring Boot application

I am trying to set a Spring Boot applications context root programmatically. The reason for the context root is we want the app to be accessed from localhost:port/{app_name} and have all the controller paths append to it. Here is the application…
CorreyS
  • 2,433
  • 3
  • 15
  • 16
226
votes
10 answers

Spring MVC - How to get all request params in a map in Spring controller?

Sample URL: ../search/?attr1=value1&attr2=value2&attr4=value4 I do not know the names of attr1, att2, and attr4. I would like to be able to do something like that (or similar, don't care, just as long as I have access to the Map of request param…
MDb
  • 2,261
  • 2
  • 14
  • 3
225
votes
7 answers

Difference between the annotations @GetMapping and @RequestMapping(method = RequestMethod.GET)

What's the difference between @GetMapping and @RequestMapping(method = RequestMethod.GET)? I've seen in some Spring Reactive examples, that @GetMapping was used instead of @RequestMapping
nowszy94
  • 3,151
  • 4
  • 18
  • 33
224
votes
8 answers

What is Dispatcher Servlet in Spring?

In this image (which I got from here), HTTP request sends something to Dispatcher Servlet. My Question is what does Dispatcher Servlet do? Is it something like getting the information thrown from the web page and throwing it to the controller?
Kevin
  • 23,174
  • 26
  • 81
  • 111
219
votes
4 answers

When use ResponseEntity and @RestController for Spring RESTful applications

I am working with Spring Framework 4.0.7, together with MVC and Rest I can work in peace with: @Controller ResponseEntity For example: @Controller @RequestMapping("/person") @Profile("responseentity") public class…
Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158