控制反转(Inversion Of Control),将对象的创建和依赖关系(对象之间的依赖关系可以通过配置文件或者注解来建立)交给第三方容器处理,用的时候告诉容器需要什么然后直接去拿就行了。
Person类作为bean
- public class Person {
- public void work(){
- System.out.println("I am working...");
- }
- }
applicationContext.xml配置bean
- "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 id="person" class="com.springframework.bean.test.Person">bean>