195-如何获取Spring容器中的对象?

    1)SpringBoot框架获取容器中的对象
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
        RestTemplate bean = (RestTemplate) context.getBean("restTemplate");
    2)Spirng框架如何获取容器中的对象呢?
        ApplicationContext context = new ClassPathXmlApplicationContext("application.xml")
        RestTemplate bean = (RestTemplate) context.getBean("restTemplate");

 

posted on 2020-05-25 14:48  十年磨三劍  阅读(646)  评论(0编辑  收藏  举报

导航