视频地址:https://www.youtube.com/watch?v=RA9ag2v4Gq8 代码地址:https://github.com/gaohanghang/Spring/blob/master/springcore

讲解

https://cdn.nlark.com/yuque/0/2021/png/576791/1617289333059-51c8e92e-2013-430c-9c1c-4b42398ace08.png#align=left&display=inline&height=540&originHeight=1080&originWidth=2234&size=356032&status=done&style=none&width=1117

https://cdn.nlark.com/yuque/0/2021/png/576791/1617289562998-36fde871-5e1a-49cc-a7a0-1f661abee665.png#align=left&display=inline&height=533&originHeight=1066&originWidth=2258&size=520671&status=done&style=none&width=1129

https://cdn.nlark.com/yuque/0/2021/png/576791/1617289706935-b01078fd-7103-43d1-892a-274b953ad028.png#align=left&display=inline&height=530&originHeight=1060&originWidth=2238&size=635226&status=done&style=none&width=1119

容器管理对象的生命周期

Application Context

https://cdn.nlark.com/yuque/0/2021/png/576791/1617289842595-19c697e3-6b22-4152-8acd-0dbb5edea94c.png#align=left&display=inline&height=520&originHeight=1040&originWidth=2264&size=506286&status=done&style=none&width=1132

Coding Step by Step 逐步编码

代码地址:https://github.com/gaohanghang/Spring/blob/master/springcore

public class Main1 {

    public static void main(String[] args) {
        EmailService emailService = new EmailService();
        emailService.sendEmail("[email protected]", "Hello from Miss Xing");
    }

}

https://cdn.nlark.com/yuque/0/2021/png/576791/1617289099660-89367c0d-b3a2-4498-8682-a83c04399d45.png#align=left&display=inline&height=849&originHeight=1698&originWidth=2768&size=355623&status=done&style=none&width=1384

BeanFactory 获取实例

public class Main2 {

    public static void main(String[] args) {
        //BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("spring.xml"));
        BeanFactory beanFactory = new ClassPathXmlApplicationContext("spring.xml");
        EmailService emailService = beanFactory.getBean("emailService", EmailService.class);

        emailService.sendEmail("[email protected]", "Hello from Miss Xing");
    }

}

https://cdn.nlark.com/yuque/0/2021/png/576791/1617289266154-1e40631a-ec79-4d72-920a-ca596fdb413a.png#align=left&display=inline&height=784&originHeight=1568&originWidth=2568&size=369513&status=done&style=none&width=1284

ApplicationContext 获取实例

通过xml获取实例

public class Main3 {

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        EmailService emailService = context.getBean("emailService", EmailService.class);

        emailService.sendEmail("[email protected]", "Hello from Miss Xing");
    }

}