WEB-INF/web.xml
<web-app>
<display-name>Archetype Created Web Application</display-name>
<!-- 声明监听器 创建容器时读取配置文件
默认 : /WEB-INF/applicationContext.xml
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
Servlet 有两种方法引入
1、
WebApplicationContext ctx = null;
String key = WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE;
ServletContext sc = getServletContext();
Object attr = sc.getAttribute(key);
if(attr != null){
ctx = (WebApplicationContext) attr;
}
2、
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
6823

被折叠的 条评论
为什么被折叠?



