美文网首页
spring两种装配模式

spring两种装配模式

作者: 毛仑上保罗先生 | 来源:发表于2019-01-01 22:23 被阅读0次
@Test
    public void getBean() throws Throwable {
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        Resource resource = resolver.getResource("classpath:beans.xml");
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
        reader.loadBeanDefinitions(resource);
        Car car = factory.getBean("car1", Car.class);
        System.out.println(car.getBrand());


        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beans.xml");
        Car car1 = applicationContext.getBean("car1", Car.class);
        System.out.println(car1.getBrand());
    }

相关文章

网友评论

      本文标题:spring两种装配模式

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