Day01 (Spring)

2018-04-26  本文已影响0人  瓜子明

IOC控制反转

创建一个Category对象c,对象c的name=category 1

    <bean name="c" class="com.how2java.pojo.Category">
        <property name="name" value="category 1" />
    </bean>

获取applicationContext.xml中名为c的Category类,b.getName()将其打印。

public class TestSpring {
 
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext(
                new String[] { "applicationContext.xml" });
 
        Category b = (Category) context.getBean("c");
         
        System.out.println(b.getName());
    }
}
上一篇 下一篇

猜你喜欢

热点阅读