Spring的三大核心思想:IOC(控制反转),DI(依赖注入),AOP(面向切面编程)。
(1)IOC(控制反转)
实现将组件间的关系从程序内部提到外部容器(spring的xml)来管理。
首先外部容器(spring.xml)中会动态的注册业务所需的对象(接口/类)
(2)DI(依赖注入)
组件之间的依赖关系由容器在应用系统运行期来决定, 也就是由容器动态地将某种依赖关系的目标对象实例注入到应用系统中的各个关联的组件之中
导入架包:
org.springframework
spring-beans
5.1.5.RELEASE
范例:
appliactionContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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