Spring框架是一个开源的应用程序框架,是针对bean的生命周期进行管理的轻量级容器。
Spring解决了开发者在J2EE开发中遇到的许多常见的问题,提供了功能强大IOC、AOP及Web MVC等功能。
Spring可以单独应用于构筑应用程序,也可以和Struts、Webwork、Tapestry等众多Web框架组合使用,并且可以与 Swing等桌面应用程序AP组合。
Spring不仅仅能应用于J2EE应用程序之中,也可以应用于桌面应用程序以及小应用程序之中。
Spring框架主要由七部分组成,分别是 Spring Core、 Spring AOP、 Spring ORM、 Spring DAO、Spring Context、 Spring Web和 Spring Web MVC。
官方文档地址:
https://docs.spring.io/spring-framework/docs/4.3.9.RELEASE/spring-framework-reference/
https://docs.spring.io/spring-framework/docs/5.2.0.RELEASE/spring-framework-reference/core.html#spring-core
中文
https://www.docs4dev.com/docs/zh/spring-framework/5.1.3.RELEASE/reference/
优点:
使用spring的jar包支持:
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-webartifactId>
<version>5.3.22version>
dependency>
七大模块:

弊端:发展了太久后,配置越来越多,人称“配置地狱”
在我们之前的业务中,用户的需求可能会影响程序的代码,可能需要修改代码,如果程序的代码量十分大,修改一次的成本十分的昂贵!
原来的方式:
private UserMapper usermapper=new UserMapperImpl();
现在将对象的传递由new变成set动态注入
private UserMapper userMapper;
public void setUserMapper(UserMapper userMapper){
this.userMapper=userMapper;
}
原来是程序控制的,现在变成用户控制了。
(1)写一个实体类
package com.pojo;
/**
* @author panglili
* @create 2022-07-23-21:40
*/
public class HelloSpring {
private String name;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
}
(2)将实体类配置在spring容器
<beans xmlns = "http://www.springframework.org/schema/beans"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd" >
<bean id="helloSpring" class="com.pojo.HelloSpring">
<property name="name" value="spring">property>
bean>
beans>
(3)测试
import com.pojo.HelloSpring;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author panglili
* @create 2022-07-23-21:43
*/
public class MyTest {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext( "application.xml");
HelloSpring hello =(HelloSpring) context.getBean("helloSpring");
System.out.println(hello.toString());
}
}