Generated by GPT-5-mini| Spring MVC | |
|---|---|
| Name | Spring MVC |
| Developer | Pivotal Software |
| Released | 2003 |
| Programming language | Java |
| Platform | Java Virtual Machine |
| License | Apache License 2.0 |
Spring MVC
Spring MVC is a Java-based web application framework for building model–view–controller applications on the Java Virtual Machine. It is part of the larger Spring Framework ecosystem developed by Pivotal Software and influenced by design patterns used in Model–View–Controller architectures and Apache Struts. Spring MVC emphasizes loose coupling, dependency injection, and pluggable view technologies for integration with JavaServer Pages, Thymeleaf, and other templating systems.
Spring MVC provides a request-driven web framework within the Spring Framework project maintained by Pivotal Software and contributors from the Open Source community. The project evolved alongside enterprise Java initiatives such as Java EE and standards like Servlet API and JSR 303 for validation. It competes and interoperates with frameworks and platforms including Apache Struts, Grails, Play Framework, and Jakarta EE solutions. Spring MVC's modularity permits integration with libraries such as Jackson (software) for JSON, Hibernate for persistence, and Mockito for testing.
The architecture centers on the DispatcherServlet front controller pattern derived from the Servlet API and influenced by Front Controller pattern descriptions in the Gang of Four literature. Core components include the DispatcherServlet, HandlerMapping implementations, HandlerAdapter implementations, ViewResolver implementations, and HandlerInterceptors. These components integrate with the ApplicationContext and benefit from Dependency injection provided by the Spring Framework. Additional modules support message conversion via HttpMessageConverter and multipart file handling leveraging Commons FileUpload or Servlet 3.0 APIs.
Incoming HTTP requests are received by the DispatcherServlet, a specialized Servlet API class that coordinates processing using HandlerMapping to find controllers and HandlerAdapter to invoke them. The DispatcherServlet consults HandlerExceptionResolver implementations for error handling and uses ViewResolver to select a rendering technology such as JSP, Thymeleaf, or FreeMarker. Filters such as those configured through FilterChain and integrations with Spring Security or CORS support often precede or wrap DispatcherServlet processing. The design allows for multiple DispatcherServlet instances per web application to isolate configuration contexts, a pattern used in enterprise deployments like those on Apache Tomcat or Jetty.
Controller components map URIs to handler methods using annotations from Spring Framework such as mapping annotations influenced by JAX-RS and RESTful conventions described by Roy Fielding. Controllers return ModelAndView objects or use @ResponseBody semantics to produce data directly, with JSON serialization often via Jackson (software) or XML via JAXB. The model is a container for data passed to the view layer, while views are resolved through ViewResolver implementations to technologies like JavaServer Pages, Thymeleaf, FreeMarker, or custom View implementations. Controller testing frequently uses testing utilities from Spring Test alongside frameworks such as JUnit and Mockito.
Spring MVC provides features for binding request parameters to JavaBeans via DataBinder and WebDataBinder classes, supporting complex property editors and conversion through Spring Conversion Service. Validation integrates with bean validation standards such as JSR 303 and Hibernate Validator using @Valid and BindingResult to capture errors. Form handling utilities include support for multipart file upload, form backing objects, and form tag libraries that interoperate with Spring Form Tag Library and templating engines like Thymeleaf. Common concerns such as cross-site request forgery mitigation are addressed with integrations to Spring Security and standard HTTP mechanisms defined in RFC 7231.
Configuration options span declarative XML historically used in early Spring Framework releases, Java-based configuration via @Configuration and @Bean introduced alongside Spring 3.0, and annotation-driven setups using @Controller, @RequestMapping, @Autowired, and other stereotype annotations. These styles enable integration with persistence technologies like Hibernate, JPA, messaging systems such as RabbitMQ and Apache Kafka, and view technologies like Thymeleaf or FreeMarker. Tools and build systems such as Maven (software) and Gradle commonly manage dependencies, while deployment targets include Apache Tomcat, Jetty, and cloud platforms like Cloud Foundry.
Testing strategies use the Spring TestContext Framework, MockMvc for controller tests, and unit testing with JUnit and Mockito. Performance tuning addresses view rendering, JSON serialization with Jackson (software), connection pooling via HikariCP or Apache DBCP, and request throughput on servlet containers such as Tomcat or Undertow. Best practices include using RESTful conventions from Roy Fielding's dissertation, separating concerns with service layers, favoring JavaConfig and minimal XML, employing validation with JSR 303, securing endpoints with Spring Security, and applying caching strategies aligned with HTTP/1.1 caching semantics and cache providers like Ehcache or Redis.
Category:Java web frameworks