IOC(容器),用来集成别的框架
1.IOC(Inversion(反转)Of Control):控制反转
控制:资源的获取方式:
主动式:
BookServlet{
BookService bs=new BookService();
AirPlane ap=new AirPlane();//复杂对象的创建是比较庞大的工程
}
被动式:资源的获取不是我们自己创建,而是交给一个容器来创建和设置
BookServlet{
BookService bs;
public void test01(){
bs.checkout();
}
}
容器:管理所有组件(有功能的类);假设,BookServlet受容器管理,BookService也受容器管理;容器可以自动探查出哪些组件(类)需要用到另一些组件(类);容器帮我们创建BookService对象,并把BookService对象赋值过去;
容器:主动的new资源变为被动的接受资源。类似于婚介所,告诉婚介所要一个怎么样的对象,婚介所自动给你安排剩下的事情,不需要自己找。
DI:(Dependency Injection)依赖注入;
容器能知道那个组件(类)运行的时候,需要另外一个类(组件);容器通过反射的形式,将容器中准备好的BookService对象注入(利用反射给属性赋值)到BookServlet
只要是容器管理的组件,都能使用容器提供的强大功能;