spring手动初始化bean

时间:2020-12-07 19:46:44

如果文件在classpath下:

ApplicationContext ctx= new ClassPathXmlApplicationContext(new String[]{“beans.xml”,”application.xml”});  

BeanFactory  factory =ctx;  

如果文件不在classpath下:

ApplicationContext ctx = new FileSystemXmlApplicationContext(new String[]{"file:D:/workspace_dna2/GdnaDataWebService/src/main/webapp/WEB-NF/applicationContext.xml", "file:D:/workspace_dna2/GdnaDataWebService/src/main/webapp/WEB-INF/xfire-servlet.xml"});