Content deleted Content added
m Fixed formatting issues. |
Code formatting. |
||
Line 17:
| license = [[Apache License]] 2.0
}}
The '''Spring Framework''' is an [[application framework]] and [[inversion of control]] [[Servlet container|container]] for the [[Java platform]].{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§2 Spring Core Tasks | p=47}} The framework's core features can be used by any Java application, but there are extensions for building [[web application]]s on top of the [[Java EE]] (Enterprise Edition) platform. The framework does not impose any specific [[programming model]].{{Citation needed|reason=Spring Web Flux Framework heavily uses the functional-programming paradigm according to Deinum and Cosmina's "Pro Spring MVC with WebFlux". Need supporting information for the claim that the framework does not impose any specific programming model|date=June 2023}}. The framework has become popular in the Java community as an addition to the [[Enterprise JavaBeans]] (EJB) model.{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§16-2 Integrating Two Systems Using JMS | pp=694-698}} The Spring Framework is [[Open-source software|open source]].{{sfn|Johnson|Hoeller|2004}}{{rp | pp=121–122}}{{sfn|Deinum|Cosmina|2021|loc=§1 Setting up a Local Development Environment | p=1}}
==Version history==
Line 92:
===Inversion of control container ===
The [[inversion of control]] (IoC) container is the core container in the Spring Framework.{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§2 Spring Core Tasks | p=47}} It provides a consistent means of configuring and managing Java objects{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§2 Spring Core Tasks | p=47}}{{sfn|Johnson|Hoeller|2004}}{{rp|pp=127–131}} using [[Reflection (computer science)|reflection]].{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§2-2 Create POJOs by Invoking a Constructor|pp=53-62}} The container is responsible for managing [[Object lifetime|object lifecycles]] of specific objects:{{sfn|Johnson|Hoeller|2004}}{{rp | p=128}} creating these objects,{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§2-1 Manage and Configure POJOs with the Spring IoC Container|pp=48-52}} calling their [[Initialization (programming)|initialization]] methods,{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§2-2 Create POJOs by Invoking a Constructor|pp=53-62}} and configuring these objects by wiring them together.{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§2-3 Use POJO References, Auto-Wiring, and Imports to Interact with Other POJOs|pp=59-67}}
In many cases, one need not use the container when using other parts of the Spring Framework, although using it will likely make an application easier to configure and customize. The Spring container provides a consistent mechanism to configure applications{{sfn | Johnson | Hoeller | 2004}}{{rp | p=122}} and integrates with almost all Java environments, from small-scale applications to large enterprise applications.
Line 101:
Objects created by the container are called managed objects or [[JavaBeans|beans]].{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§2-16 Use Property Editors in Spring|pp=112-116}} The container can be configured by loading [[XML]] (Extensible Markup Language) files{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§2-1 Manage and Configure POJOs with the Spring IoC Container | pp=48-52}}{{sfn | Johnson | Hoeller | 2004}}{{rp|pp=151–152}} or detecting specific [[Java annotation]]s on configuration classes. These data sources contain the bean definitions that provide the information required to create the beans.
The {{
====Types of Inversion of Control ====
There are several types of Inversion of Control. Dependency injection and dependency lookup are examples of Inversion of Control.{{sfn | Cosmina | Harrop | Schaefer | Ho | 2017 | loc
=====Dependency Injection=====
{{main article | Dependency injection}}
Dependency injection is a pattern where the container passes objects{{sfn | Johnson | Hoeller | 2004}}{{rp | p=128}} by name to other objects, via either [[constructor (computer science)|constructor]]s,{{sfn | Johnson | Hoeller | 2004}}{{rp | p=128}} [[Property (programming)|properties]], or [[Factory method pattern|factory methods]]. There are several ways to implement dependency injection: constructor-based dependency injection, setter-based dependency injection and field-based dependency injection.{{sfn | Deinum | Cosmina | 2021 | loc=§2 Spring Framework Fundamentals - Dependency Injection | pp=26-32}}
=====Dependency Lookup=====
Line 116:
The Spring framework has a feature known as autowiring, which use the spring container to automatically satisfy the dependencies specified in the JavaBean properties to objects of the appropriate type in the current factory.{{sfn | Johnson | Hoeller | 2004 | loc=§6 Lightweight Containers and Inversion of Control - IOC Containers | pp=135–137}} This can only occur if there is only one object with the appropriate type.{{sfn | Johnson | Hoeller | 2004 | loc=§6 Lightweight Containers and Inversion of Control - IOC Containers | pp=135–137}}
There are several annotations that can be used for autowiring POJOs, including the Spring-specific annotation {{
The {{
The {{
The {{
===Relationship with Jakarta Enterprise Beans (EJB)===
Line 221:
===Model–view–controller framework===
[[File:Spring5JuergenHoeller2.jpg|thumb|Spring MVC/Web Reactive presentation given by Jürgen Höller]]
The Spring Framework features its own [[model–view–controller]] (MVC) [[web application framework]],{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§4 Spring @MVC | p=217}} which was not originally planned. The Spring developers decided to write their own Web framework as a reaction to what they perceived as the poor design of the (then) popular [[Jakarta Struts]] Web framework,<ref>[http://www.theserverside.com/tt/articles/article.tss?l=SpringFramework Introduction to the Spring Framework]</ref>{{Failed verification|date=June 2023}} as well as deficiencies in other available frameworks. In particular, they felt there was insufficient separation between the presentation and request handling layers, and between the request handling layer and the model.<ref>Johnson, Expert One-on-One J2EE Design and Development, Ch. 12. et al.</ref>
Like Struts, Spring MVC is a request-based framework.{{sfn | Johnson | Hoeller | 2004}}{{rp | p=375}} The framework defines [[strategy pattern|strategy]] interfaces{{sfn | Johnson | Hoeller | 2004}}{{rp | p=144}} for all of the responsibilities that must be handled by a modern request-based framework. The goal of each interface is to be simple and clear so that it's easy for Spring MVC users to write their own implementations, if they so choose. MVC paves the way for cleaner front end code. All interfaces are tightly coupled to the [[Java Servlet|Servlet API]]. This tight coupling to the Servlet API is seen by some as a failure on the part of the Spring developers to offer a high level of abstraction for Web-based applications {{Citation needed|date=February 2007}}. However, this coupling ensures that the features of the Servlet API remain available to developers while offering a high abstraction framework to ease working with it.
Line 234:
* <code>LocaleResolver</code>: responsible for resolving and optionally saving of the [[locale (computer software)|locale]] of an individual user.{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§4-4 Resolving User Locales | pp=239-240}}
* <code>MultipartResolver</code>: facilitate working with file uploads by wrapping incoming requests.{{sfn | Deinum | Cosmina | 2021 | loc=§4 Spring MVC Architecture - Prepare a request | pp=75-76}}
* <code>View</code>: responsible for returning a response to the client. The <code>View</code> should not contain any business logic and should only present the data encapsulated by the <code>Model</code>.{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§4 Spring @MVC | p=217}} Some requests may go straight to <code>View</code> without going to the <code>Model</code> part; others may go through all three.
* <code>ViewResolver</code>: responsible for selecting a <code>View</code> based on a logical name for the <code>View</code>{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§4-6 Resolving Views by Names|pp=243-247}}{{sfn | Deinum | Cosmina | 2021 | loc=§4 Spring MVC Architecture - Render a view | p=81}} (use is not strictly required{{sfn | Johnson | Hoeller | 2004}}{{rp | p=511}}).
* <code>Model</code>: responsible for encapsulating business data.{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§4-6 Resolving Views by Names|pp=243-247}} The <code>Model</code> is exposed to the view by the controller.{{sfn | Johnson | Hoeller | 2004}}{{rp | p=374}} (use is not strictly required).
Line 240:
Each strategy interface above has an important responsibility in the overall framework. The abstractions offered by these interfaces are powerful, so to allow for a set of variations in their implementations.{{sfn | Johnson | Hoeller | 2004}}{{rp | p=144}} Spring MVC ships with implementations of all these interfaces and offers a feature set on top of the Servlet API. However, developers and vendors are free to write other implementations. Spring MVC uses the Java {{Javadoc:SE|package=java.util|java/util|Map}} interface as a data-oriented abstraction for the <code>Model</code> where keys are expected to be {{Javadoc:SE|java/lang|String}} values.{{Citation needed|date=June 2023}}
The ease of testing the implementations of these interfaces is one important advantage of the high level of abstraction offered by Spring MVC.{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§17 Spring Testing | p=723}}{{sfn | Johnson | Hoeller | 2004}}{{rp | p=324}} <code>DispatcherServlet</code> is tightly coupled to the Spring inversion of control container for configuring the web layers of applications. However, web applications can use other parts of the Spring Framework, including the container, and choose not to use Spring MVC.
====A workflow of Spring MVC====
When a user clicks a link or submits a form in their web-browser, the request goes to the Spring <code>DispatcherServlet</code>. <code>DispatcherServlet</code> is a [[Front controller|front-controller]] in Spring MVC.{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§4-1 Developing a Simple Web Application with Spring MVC|pp=217-232}}{{sfn | Deinum | Cosmina | 2021 | loc=§4 Spring MVC Architecture - DispatcherServlet Request Processing Workflow|pp=73-74}} The <code>DispatcherServlet</code> is highly customizable and flexible.{{sfn|Deinum|Cosmina|2021|loc=§4 Spring MVC Architecture - DispatcherServlet Request Processing Workflow|pp=73-74}} Specifically, it is capable of handling more types of handlers than any implementations of <code>org.
springframework.web.servlet.mvc.Controller</code> or <code>org.
springframework.stereotype.Controller</code> annotated classes.{{sfn|Deinum|Cosmina|2021|loc=§4 Spring MVC Architecture - DispatcherServlet Request Processing Workflow|pp=73-74}} It consults one or more handler mappings.{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§4-1 Developing a Simple Web Application with Spring MVC|pp=217-232}} <code>DispatcherServlet</code> chooses an appropriate controller and forwards the request to it. The <code>Controller</code> processes the particular request and generates a result. It is known as <code>Model</code>. This information needs to be formatted in html or any front-end technology like [[Jakarta Server Pages]] (also known as JSP){{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§4-1 Developing a Simple Web Application with Spring MVC|pp=217-232}}{{sfn|Walls|2019 | p=35}} or [[Thymeleaf]].{{sfn|Walls|2019 | p=35}} This is the <code>View</code> of an application.{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§4-1 Developing a Simple Web Application with Spring MVC|pp=217-232}} All of the information is in the <code>Model</code> And <code>View</code> object. When the controller is not coupled to a particular view, <code>DispatcherServlet</code> finds the actual <code>View</code> (such as JSP) with the help of <code>ViewResolver</code>.{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§4-1 Developing a Simple Web Application with Spring MVC|pp=217-232}}{{sfn | Johnson | Hoeller | 2004}}{{rp | pp=390–391}}
====Configuration of DispatcherServlet====
Line 276:
* HTTP-based protocols
** [[Hessian (Web service protocol)|Hessian]]: binary serialization protocol,{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§14-8 Expose and Invoke Services through HTTP|pp=632-635}}{{sfn | Johnson | Hoeller | 2004}}{{rp | p=335}} open-sourced{{sfn | Johnson | Hoeller | 2004}}{{rp | p=335}} and maintained by [[Common Object Request Broker Architecture|CORBA]]-based protocols{{Citation needed|reason=Sources such as "Expert One-on-One J2EE Design and Development" by Rod Johnson or "Spring Recipes" by Deinum et Al. only mention that the Hessian is maintained by the company "Caucho" and they do not explicity mention that the Hessian is maintained by CORBA-based protocols|date=June 2023}}. Hessian is maintained by the company [[Caucho Technology|Caucho]].{{sfn | Johnson | Hoeller | 2004}}{{rp | p=335}} Hessian is suitable for stateless remoting needs, in particular, Java-to-Java communication.{{sfn | Johnson | Hoeller | 2004}}{{rp|pp=335–336}}
** Burlap: An [[Xml based language|XML-based]] binary protocol that is open-sourced and also maintained by the company [[Caucho Technology|Caucho]].{{sfn|Deinum|Rubio|Long|Mak|2014|loc=§14-8 Expose and Invoke Services through HTTP|pp=632-635}}{{sfn | Johnson | Hoeller | 2004}}{{rp | p=335}} The only advantage of using Burlap instead of Hessian is that it is [[XML parser|XML-parsable]] and [[Human readable code|human readable]].{{sfn | Johnson | Hoeller | 2004}}{{rp | p=335}} For Java-to-Java communication, the Hessian is preferred since it is more light-weight and efficient.{{sfn|Johnson|Hoeller|2004}}{{rp | p=335}}
** [[Java remote method invocation|RMI]] (1): method invocations using RMI infrastructure yet specific to Spring{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§14-7 Expose and Invoke Services through RMI|pp=627-632}}
** RMI (2): method invocations using RMI interfaces complying with regular RMI usage{{sfn | Deinum | Rubio | Long | Mak | 2014 | loc=§14-7 Expose and Invoke Services through RMI|pp=627-632}}
Line 298:
====Spring Boot====
{{main article|Spring Boot}}
[[Spring Boot]] Extension is Spring's [[Convention over configuration|convention-over-configuration]] solution for creating [[standalone application|stand-alone]], production-grade{{sfn|Walls|2016|loc=§foreword | p=vii}} Spring-based Applications that you can "just run".<ref>{{cite web|url=http://projects.spring.io/spring-boot/|title=Spring Boot|publisher=spring.io}}</ref> It is preconfigured with the Spring team's "opinionated view"{{sfn | Walls | 2016 | loc=§2.4 | p=48}}{{sfn|Deinum|Cosmina|2021|loc=§2 Spring Framework Fundamentals |
Key Features:
|