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());
}
}
网友评论