Spring 入门学习手札(二)通过XML定义Bean
一、定义一个Bean:
public class WarOfPirate { public static void main(String[] args) throws Exception { BeanFactory factory = new XmlBeanFactory(new FileSystemResource("ship.xml")); PirateShip jacksShip = (PirateShip)factory.getBean("jacksShip"); ... } }4、通过BeanFactory加载ship.xml(之前xml的名称),然后从中取出jacksShip bean注入到main函数中的jacksShip中。
杰克船长从xml手中获取了黑珍珠号……