美文网首页
2018-07-04 Spring 入门配置,概念,约束

2018-07-04 Spring 入门配置,概念,约束

作者: 培根好吃 | 来源:发表于2018-07-04 10:40 被阅读0次
    image.png
    image.png

    IOC 控制反转,将对象的创建权反转给了spring
    DI 依赖注入前提是必须有IOC的环境,Spring管理这个类的时候将类依赖的属性注入进来。也就是设置属性

    面向对象的三种关系
    依赖 B中的方法需要调用A,那么B依赖了A
    继承
    聚合 has A 分为 松散,起闭。足球队没有守门员也能打球,是松散。人没有脑子就无法生存,是起闭。

    BeanFactory和ApplicationContext不同。
    bd是在调用getBean时创建的。而ac是在调用配置文件时创建的

    
    <bean id="Liyu" class="com.ryan.test.Xiaoliyu"></bean>
    
    package com.ryan.test;
    
    import org.apache.catalina.core.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class Test {
       private static Object bean;
    
    public static void main(String[] args) {
         ClassPathXmlApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
         Liyu liyu= (Liyu)applicationContext.getBean("Liyu");
         liyu.draw();
       }
    }
    

    相关文章

      网友评论

          本文标题:2018-07-04 Spring 入门配置,概念,约束

          本文链接:https://www.haomeiwen.com/subject/pcxeuftx.html