使用resource接口表示一个与来源无关的资源,code表示spring配置文件。
xmlbeanfactory 通过resource装载spring的配置信息,并启动ioc容器,通过getBean从ioc容器中获取bean;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class BeanExample{
public static void main(String[] args){
Resource resource = new ClassPathResource(
"springContext.xml");
BeanFactory beanFactory = new XmlBeanFactory(resource);
ExampleBean example= (ExampleBean ) beanFactory
.getBean("example");
example.test();
}