初识Spring框架实现IOC和DI(依赖注入)

时间:2023-03-05 22:27:14

学习过Spring框架的人一定都会听过Spring的IoC(控制反转) 、DI(依赖注入)这两个概念,对于初学Spring的人来说,总觉得IoC 、DI这两个概念是模糊不清的,是很难理解的,

IoC是什么

  Ioc—Inversion of Control,即“控制反转”,不是什么技术,而是一种设计思想。

  在Java开发中,Ioc意味着将你设计好的对象交给容器控制,而不是传统的在你的对象内部直接控制。如何理解好Ioc呢?理解好Ioc的关键是要明确“谁控制谁,控制什么,为何是反转(有反转就应该有正转了),哪些方面反转了”,那我们来深入分析一下:

  ●谁控制谁,控制什么:传统Java SE程序设计,我们直接在对象内部通过new进行创建对象,是程序主动去创建依赖对象;而IoC是有专门一个容器来创建这些对象,即由Ioc容器来控制对 象的创建;谁控制谁?当然是IoC 容器控制了对象;控制什么?那就是主要控制了外部资源获取(不只是对象包括比如文件等)。

  ●为何是反转,哪些方面反转了:有反转就有正转,传统应用程序是由我们自己在对象中主动控制去直接获取依赖对象,也就是正转;而反转则是由容器来帮忙创建及注入依赖对象;为何是反转?因为由容器帮我们查找及注入依赖对象,对象只是被动的接受依赖对象,所以是反转;哪些方面反转了?依赖对象的获取被反转了。

  用图例说明一下,传统程序设计如图2-1,都是主动去创建相关对象然后再组合起来:

                          初识Spring框架实现IOC和DI(依赖注入)

当有了IoC/DI的容器后,在客户端类中不再主动去创建这些对象了,如图2-2所示:

                           aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAVQAAAGiCAIAAAA3O6nmAAAgAElEQVR4nO29b3Bkx3UfOt+oT9qk6oX8Io4AW7OKZXKJmAAZk0PWg2XDUCoiMVUmhIq565hjCLI35lrEGKCfaS3EqVmWmAAEkxEtgAVS8SCQkZJAjVhr1lJIBiqUBNk10EYGQzzEvt4Qr4IthX7cUlB5SJQP8z78hJOz3X379r0zmDuDe079amv24v7p27d/fU6fPn061RAREUmkpOIugIiISDwi5BcRSagI+UVEEipCfhGRhIqQv9Pl4OCgVqvRf2u12sHB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Zz1JBD5dfc41vnzfpMHNRk/EAoGP4Je8qHhweZX2nfjXmBCfpX8WJ06O1+kCTm/JbGYq6PoXf5FsWDWO14WCieWsa0ri8b1MBu7ujBm+6GmH0HzK1qUOiPucdjZ3fTjLYgNQ9e4KpFOs+/YW726DFe534QZXbuwNOc3ecZjK73jgZJSJCy5i8yfajfvBSbkP9kcftWry4HGnt8JTQ4U4zIyUez1jbVOs3KNddJkITtEh0eDkF8SeAoSCiG/kF+QUAj5hfyChELIL+QXJBRCfiG/IKEQ8gv5BQmFkF/IL0gohPxCfkFCkWjy37x580MfuiMlIpJUue++c61iU3ukZeQXERHpLhHyi4gkVIT8IiIJFSG/iEhC5f8HDkNkLrqkgUQAAAAASUVORK5CYII=" alt="" />

以上就是简单的IOC的理解

那么接下来我们就来实现下我们自己的第一个Spring示例

1.1我们准备一个HelloWord类

package cn.ljy.clazz;

public class HelloWord {
//名称
private String name;
//性别
private String sex;
//年龄
private int age;
//体重
private double weight; //准备构造函数 //无参构造 初始化IOC容器时需要
public HelloWord() { } //姓名 性别 年龄的构造
public HelloWord(String name, String sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
} //姓名 性别 体重的构造
public HelloWord(String name, String sex, double weight) {
this.name = name;
this.sex = sex;
this.weight = weight;
} public String sayHello(){
return "HelloWord"+name;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} @Override
public String toString() {
return "HelloWord [name=" + name + ", sex=" + sex + ", age=" + age
+ ", weight=" + weight + "]";
} }

1.2我们必须得准备一个applicationContext.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"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd
">
<!-- 将 HelloWord 类交给Spring容器进行管理-->
<!-- 通过属性的方式传入参数 -->
<bean id="HelloWord" class="cn.ljy.clazz.HelloWord">
<!-- 为参数赋值 -->
<property name="name" value="巴黎的雨季"></property>
</bean>
</beans>

初识Spring框架实现IOC和DI(依赖注入)

这样就整理好了第一个配置文件了,然后我们进行一道测试

package cn.ljy.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import cn.ljy.clazz.HelloWord;
import cn.ljy.clazz.NewPeople;
import cn.ljy.clazz.People;
import cn.ljy.clazz.Person; public class MyTest {
public static void main(String[] args) {
//实例化Spring容器的上下文 (创建IOC容器)
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
//通过ApplicationContext的getBean()方法,根据id来获取Bean的实例
HelloWord hello = (HelloWord)context.getBean("HelloWord");
//调用HelloWord类中的方法
System.out.println("通过属性的方式给name赋值:");
String result = hello.sayHello();
System.out.println(result); }

实现结果为:

初识Spring框架实现IOC和DI(依赖注入)

1.3以上在配置文件中使用的是setter方法依赖注入,接下来我们使用构造器的方式来实现依赖注入

applicationContext.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"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd
">
<!-- 将 HelloWord 类交给Spring容器进行管理-->
<!-- 通过构造器的方式传入参数 -->
<bean id="AttributeByConstructor1" class="cn.ljy.clazz.HelloWord">
<!-- 通过构造器方式传参 -->
<constructor-arg value="巴黎的雨季" index=""/>
<constructor-arg value="男" index=""/>
<constructor-arg value="" type="int"/>
</bean>
</beans>

初识Spring框架实现IOC和DI(依赖注入)

执行结果如图

初识Spring框架实现IOC和DI(依赖注入)

1.4使用引用类型,引用自定义的Bean(外部Bean)

准备一个person对象

package cn.ljy.clazz;

public class Person {
private String name;
private int age;
private Car car; public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Car getCar() {
return car;
}
public void setCar(Car car) {
this.car = car;
}
@Override
public String toString() {
return "Person [name=" + name + ", age=" + age + ", car=" + car + "]";
} }

applicationContext.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"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd
"> <!-- 监管Car 准备三car-->
<bean id="car" class="cn.ljy.clazz.Car">
<property name="brand" value="奔驰"></property>
<property name="business" value="上海"></property>
<property name="price" value=""></property>
</bean>     <!-- 配置person 引用Car -->
<bean id="person" class="cn.ljy.clazz.Person">
<property name="name" value="巴黎的雨季"></property>
<property name="age" value=""></property>
<property name="car" ref="car"></property>
</bean>
</bean>
</beans>

初识Spring框架实现IOC和DI(依赖注入)

执行结果

初识Spring框架实现IOC和DI(依赖注入)

1.5使用内部Bean

<!-- 内部bean   -->
<bean id="person2" class="cn.ljy.clazz.Person">
<property name="name" value="巴黎的雨季"></property>
<property name="age" value=""></property>
<!-- 注意:内部bean只能在内部使用,不能被外部所引用 -->
<property name="car" >
<bean class="cn.ljy.clazz.Car">
<property name="brand" value="福特"></property>
<property name="business" value="北京"></property>
<property name="price" value=""></property>
</bean>
</property>
</bean>

初识Spring框架实现IOC和DI(依赖注入)

执行结果与上一步基本一致

1.6配置list集合属性

People

package cn.ljy.clazz;

import java.util.List;

public class People {

    private String name;
private int age;
private List<Car> cars; public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public List<Car> getCars() {
return cars;
}
public void setCars(List<Car> cars) {
this.cars = cars;
}
@Override
public String toString() {
return "People [name=" + name + ", age=" + age + ", cars=" + cars + "]";
} }
<!-- list集合属性的配置 -->
<bean id="people" class="cn.ljy.clazz.People">
<property name="name" value="巴黎的雨季"></property>
<property name="age" value=""></property>
<property name="cars">
<!-- 使用list节点为集合属性赋值 -->
<list>
<ref bean="car"/>
<ref bean="car2"/>
<ref bean="car3"/>
</list>
</property>
</bean>

初识Spring框架实现IOC和DI(依赖注入)

执行结果

初识Spring框架实现IOC和DI(依赖注入)

1.7使用Map集合配置属性

NewPeople

package cn.ljy.clazz;

import java.util.Map;
import java.util.Properties; public class NewPeople {
private String name;
private int age;
private Map<String,Car> cars; //配置properties属性
private Properties properties; public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Map<String, Car> getCars() {
return cars;
}
public void setCars(Map<String, Car> cars) {
this.cars = cars;
} public Properties getProperties() {
return properties;
}
public void setProperties(Properties properties) {
this.properties = properties;
}
@Override
public String toString() {
return "NewPeople [name=" + name + ", age=" + age + ", cars=" + cars
+ "]";
} }
 <!--Map集合属性值的配置  -->
<bean id="people2" class="cn.ljy.clazz.NewPeople">
<property name="name" value="巴黎的雨季"></property>
<property name="age" value=""></property>
<property name="cars">
<map>
<entry key="OneCar" value-ref="car"></entry>
<entry key="TwoCar" value-ref="car2"></entry>
<entry key="Three">
<bean class="cn.ljy.clazz.Car">
<property name="brand" value="法拉利"></property>
<property name="business" value="上海"></property>
<property name="price" value=""></property>
</bean>
</entry>
</map>
</property>
</bean>

初识Spring框架实现IOC和DI(依赖注入)

以上就是一些基本的常用的依赖注入了,还有几个例子我会在下面的代码中贴出来,因为用的不多,所以就不做详细的讲解了

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
"> <!-- 将 HelloWord 类交给Spring容器进行管理--> <!-- 通过属性的方式传入参数 -->
<bean id="HelloWord" class="cn.ljy.clazz.HelloWord">
<!-- 为参数赋值 -->
<property name="name" value="巴黎的雨季"></property>
</bean> <!-- 通过构造器的方式传入参数 -->
<bean id="AttributeByConstructor1" class="cn.ljy.clazz.HelloWord">
<!-- 通过构造器方式传参 -->
<constructor-arg value="巴黎的雨季" index=""/>
<constructor-arg value="男" index=""/>
<constructor-arg value="" type="int"/>
</bean> <!--给第二个构造器赋值 -->
<bean id="AttributeByConstructor2" class="cn.ljy.clazz.HelloWord">
<!-- 通过构造器方式传参 -->
<constructor-arg value="巴黎的雨季" index=""/>
<constructor-arg name="sex" value="男" />
<constructor-arg value="" type="double"/>
</bean> <!-- 监管Car 准备三car-->
<bean id="car" class="cn.ljy.clazz.Car">
<property name="brand" value="奔驰"></property>
<property name="business" value="上海"></property>
<property name="price" value=""></property>
</bean>
<bean id="car2" class="cn.ljy.clazz.Car">
<property name="brand" value="大众"></property>
<property name="business" value="广州"></property>
<property name="price" value=""></property>
</bean>
<bean id="car3" class="cn.ljy.clazz.Car">
<property name="brand" value="雪佛兰"></property>
<property name="business" value="深圳"></property>
<property name="price" value=""></property>
</bean> <!-- 配置person 引用Car -->
<bean id="person" class="cn.ljy.clazz.Person">
<property name="name" value="巴黎的雨季"></property>
<property name="age" value=""></property>
<property name="car" ref="car"></property>
</bean> <!-- 内部bean -->
<bean id="person2" class="cn.ljy.clazz.Person">
<property name="name" value="巴黎的雨季"></property>
<property name="age" value=""></property>
<!-- 注意:内部bean只能在内部使用,不能被外部所引用 -->
<property name="car" >
<bean class="cn.ljy.clazz.Car">
<property name="brand" value="福特"></property>
<property name="business" value="北京"></property>
<property name="price" value=""></property>
</bean>
</property>
</bean> <!-- 级联属性的使用 -->
<bean id="person3" class="cn.ljy.clazz.Person">
<property name="name" value="巴黎的雨季"></property>
<property name="age" value=""></property>
<property name="car" ref="car"></property>
<!-- 级联,改变原来的值 注意:必须是存在car对象才可以,Spring不会自动的创建car -->
<property name="car.brand" value="劳斯莱斯"></property>
</bean> <!-- list集合属性的配置 -->
<bean id="people" class="cn.ljy.clazz.People">
<property name="name" value="巴黎的雨季"></property>
<property name="age" value=""></property>
<property name="cars">
<!-- 使用list节点为集合属性赋值 -->
<list>
<ref bean="car"/>
<ref bean="car2"/>
<ref bean="car3"/>
</list>
</property>
</bean> <!--Map集合属性值的配置 -->
<bean id="people2" class="cn.ljy.clazz.NewPeople">
<property name="name" value="巴黎的雨季"></property>
<property name="age" value=""></property>
<property name="cars">
<map>
<entry key="OneCar" value-ref="car"></entry>
<entry key="TwoCar" value-ref="car2"></entry>
<entry key="Three">
<bean class="cn.ljy.clazz.Car">
<property name="brand" value="法拉利"></property>
<property name="business" value="上海"></property>
<property name="price" value=""></property>
</bean>
</entry>
</map>
</property>
</bean> <!-- 配置properties属性-->
<bean id="people3" class="cn.ljy.clazz.NewPeople">
<property name="name" value="巴黎的雨季"></property>
<property name="age" value=""></property>
<property name="properties">
<props>
<prop key="user">root</prop>
<prop key="password"></prop>
<prop key="jdbcurl">jdbc:mysql:/test</prop>
<prop key="drivarClass">com.mysql.jdbc.java</prop>
</props>
</property>
</bean> <!-- 独立出一个bean 比如说list 需要引入新的命名空间 util-->
<!-- <util:list id="cars">
<ref bean="car"/>
<ref bean="car2"/>
<ref bean="car3"/>
</util> <bean id="people4" class="cn.ljy.clazz.People">
<property name="name" value="巴黎的雨季"></property>
<property name="age" value=""></property>
<property name="cars" ref="cars"></property>
</bean> --> <!-- 自动装配
可以使用autowire属性指定自动装配的方式
byName 根据Bean的名字和当前Bean的setter风格的属性名进行自动装配,若有匹配的,则进行自动装配 ,若没有匹配的则不进行装配
byType 根据Bean的类型和当前Bean的属性的类型进行自动装配,若IOC容器中定义了多个类型匹配的Bean 则会抛出异常
-->
<bean id="person4" class="cn.ljy.clazz.Person" autowire="byName">
<property name="name" value="巴黎的雨季"></property>
<property name="age" value=""></property>
</bean> </beans>

相关文章