Spring Framework: Difference between revisions

Content deleted Content added
Fixed typo in Modules section for the Data access item
 
(6 intermediate revisions by 4 users not shown)
Line 25:
! Version
! Date
! Notes
|-
| 0.9 || 2003 ||
|-
| 1.0 || March 24, 2004 || First production release.
|-
| 2.0 || 2006 ||
|-
| 3.0 || 2009 ||
|-
| 4.0 || 2013 ||
|-
| 5.0 || 2017 ||
|-
| 6.0 || November 22, 2022 ||
|-
| 6.1 || November 16, 2023 ||
|-
| 6.2 || scheduledNovember for release in November14, 2024 ||
|-
|}
Line 88 ⟶ 87:
Objects created by the container are called managed objects or [[JavaBeans|beans]].{{sfn | Deinum | Long | Mak | Rubio | 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 | Long | Mak | Rubio | 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 {{code|@Configuration}} is a Spring-specific annotation that marks a class as the configuration class. The configuration class provides the beans to the Spring {{code|ApplicationContext}}.{{sfn|Walls|2019|loc=§1.1 Getting started with Spring - What is Spring|pp=4-6}} Each of the methods in the Spring configuration class is configured with the {{code|@Bean}} annotation. The {{code|ApplicationContext}} interface will then return the objects configured with the {{code|@Bean}} annotation as beans. The advantage of javaJava-based configuration over XML-based configuration is better type safety and refactorability.{{sfn|Walls|2019|loc=§1.1 Getting started with Spring - What is Spring | pp=4-6}}
 
==== Types of Inversion of Control ====
Line 101 ⟶ 100:
 
====Autowiring====
The Spring framework has a feature known as autowiring, which uses the springSpring 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 {{code|@Autowire}} (as well as several other Spring-specific annotations that help resolve autowire ambiguity such as the {{code|@Qualifier}} or {{code|@Primary}} annotations),{{sfn | Deinum | Long | Mak | Rubio | 2014 | loc=§3-3 Use POJO References and Auto-Wiring to Interact with other POJOs |pp=145-151}}{{sfn | Cosmina | Harrop | Schaefer | Ho | 2017 | loc=§3 Introducing IoC and DI in Spring - Autowiring Your Beans | pp=112-120 }} and the standard Java annotations {{code|@Resource}} and {{code|@Inject}}.{{sfn | Deinum | Long | Mak | Rubio | 2014 | loc=§3-4 Auto-wire POJOs the @Resource and @Inject annotation | pp=151-154}}
 
The {{code|@Qualifier}} annotation can be used on a class that defines a bean to inform Spring to prioritize the bean creation when autowiring it by '''name'''.{{sfn | Cosmina | Harrop | Schaefer | Ho | 2017 | loc=§3 Introducing IoC and DI in Spring - Autowiring Your Beans | pp=112-120 }}
 
The {{code|@Primary}} annotation can be used on a class that defines a bean to inform Spring to prioritize the bean creation when autowiring it by '''type'''.{{sfn | Cosmina | Harrop | Schaefer | Ho | 2017 | loc=§3 Introducing IoC and DI in Spring - Autowiring Your Beans | pp=112-120 }}
 
The {{code|@Resource}} annotation is an annotation that conforms to [[JSR 250]], or Common Annotations for the Java Platform., The {{code|@Resource}} annotationand is used for autowiring references to POJOs by '''name'''.{{sfn | Deinum | Long | Mak | Rubio | 2014 | loc=§3-4 Auto-wire POJOs the @Resource and @Inject annotation | pp=151-154}}

The {{code|@Inject}} annotation is an annotation that conforms to JSR 300, or Standard Annotations for injection., The {{code|@Inject}} annotationand is used for autowiring references to POJOs by '''type'''.{{sfn | Deinum | Long | Mak | Rubio | 2014 | loc=§3-4 Auto-wire POJOs the @Resource and @Inject annotation | pp=151-154}}
 
===Aspect-oriented programming framework===
Line 121 ⟶ 122:
Spring AOP has been designed to work with cross-cutting concerns inside the Spring Framework.{{sfn | Johnson | Hoeller | 2004}}{{rp | p=473}} Any object which is created and configured by the container can be enriched using Spring AOP.
 
The Spring Framework uses Spring AOP internally for transaction management, security, remote access, and [[Java Management Extensions|JMX]].<ref>{{Citationcite book |last=Chidester |first=Ashlan |title=Looking Forward to the Spring Framework needed|date=June2024 |publisher=Kindle Edition |url=https://www.amazon.com/dp/B0CFYBPFLQ?ref=KC_GS_GB_US |access-date=February 12, 20232025}}</ref>
 
Since version 2.0 of the framework, Spring provides two approaches to the AOP configuration: