spring IOC DI 已经spring工厂类

IOC为控制反转,是将bean类的初始化控制权,创建权交给spring框架,而不用new一个新对象。

DI为依赖注入,是为bean类注入属性,set注入,构造器注入。

<bean id="userService" class="com.imooc.ioc.demo1.UserServiceImpl">
        <property name="name" value="李四"/>
    </bean>

spring工厂类:(传统工厂类BeanFactory)

ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");

使用ApplicationContext时是在启动时就加载配置文件中的bean类使其实例化。

猜你喜欢

转载自blog.csdn.net/song_chengbo/article/details/97396484