http://flatfish2000.iteye.com/blog/465667
- ApplicationContext ac = new FileSystemXmlApplicationContex("applicationContext.xml");
- ac.getBean("beanId");
ClassPathXmlApplicationContext app = new ClassPathXmlApplicationContext("appliactionContext.xml");
- ApplicationContext ac1 = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletContext sc)
- ApplicationContext ac2 = WebApplicationContextUtils.getWebApplicationContext(ServletContext sc)
- ac1.getBean("beanId");
- ac2.getBean("beanId");
import org.springframework.web.context.support.WebApplicationContextUtils;
ApplicationContext ac1 = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletContext sc)
ApplicationContext ac2 = WebApplicationContextUtils.getWebApplicationContext(ServletContext sc)
ac1.getBean("beanId");
ac2.getBean("beanId");
public class DicBean implements ServletContextAware{
private ServletContext servletContext;
public void setServletContext(ServletContext sc) {
this.servletContext=sc;
System.out.println("项目的绝对路径为:"+servletContext.getRealPath("/"));
}
}