spring mvc怎么获取web-inf路径
1个回答
推荐于2016-06-30 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517196
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.SystemUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
--------------------------------------------------------------------------------------------------
System.out.println(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); //得到org.springframework.web.context.WebApplicationContext.ROOT
System.out.println(request.getSession().getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)); //Root WebApplicationContext: startup date [Thu Aug 30 21:18:34 CST 2012]; root of context hierarchy
System.out.println(request.getSession().getServletContext()); //得到org.apache.catalina.core.ApplicationContextFacade
--------------------------------------------------------------------------------------------------
ServletContext servletContext = request.getSession().getServletContext();
WebApplicationContext wctx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
System.out.println(wctx.getBean("localQuartzScheduler")); //得到org.quartz.impl.StdScheduler
ApplicationContext context = new FileSystemXmlApplicationContext("file:D:/Tomcat 7.0/webapps/SpringMvcWs/" + "WEB-INF" + SystemUtils.FILE_SEPARATOR + "applicationContext.xml");
System.out.println(context.getBean("localQuartzScheduler")); //得到org.quartz.impl.StdScheduler
--------------------------------------------------------------------------------------------------
ApplicationContext cpxac = new ClassPathXmlApplicationContext("applicationContext.xml"); //如果applicationContext.xml在工程的src目录下
System.out.println(cpxac.getBean("localQuartzScheduler")); //得到org.quartz.impl.StdScheduler
ApplicationContext classpathcpxac = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); //如果applicationContext.xml在工程的src目录下
System.out.println(classpathcpxac.getBean("localQuartzScheduler")); //得到org.quartz.impl.StdScheduler
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询