和XmlBeanFactory 容器类几乎一样,
只不过BeanFactory容器更轻量化,也是采用DI(依赖注入)的方式.
package test; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.ClassPathResource; public class MainApp { public static void main(String[] args) { BeanFactory factory = new XmlBeanFactory(new ClassPathResource("Beans.xml")); HelloWorld obj = (HelloWorld)factory.getBean("helloworld"); obj.getMessage(); } }