您的位置:首页 > 移动开发 > WebAPP

JavaWeb学习笔记-spring-03-ioc-WebApplicationContext

2018-02-11 15:06 561 查看

WebApplicationContext

WebApplicationContextUtils.getWebApplicationContext(ServletContext sc)

web.xml

Servlet

org.springframework.web.context.ContextLoaderServlet//已移除

Lintener

org.springframework.web.context.ContextLoaderListener

<!-- ContextLoaderistener启动WebApplicationContext具体配置-->
<!-- 指定配置文件-->
<context-param>
<param-name>contextConfigLoaction</param-name>
<param-value>Application-context.xml</param-value>
</context-param>
<!-- 声明web容器监听器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listen
4000
er-class>
</listener>


<!-- 通过指定context参数,让spring使用AnnotationConfigWebApplicationContext而非XmlWebApplicationContext启动容器-->
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<!-- 指定标注了@CfigurationLocation的配置类,多个可以使用逗号或空格分隔-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.config</param-value>
</context-param>
<!-- ContextLoaderListener监听器将根据上面配置使用AnnotationConfigWebApplicationContext
根据contextConfigLocation指定配置类启动Spring容器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


资源加载

classpath: classpath:com/xxx/beans.xml(“classpath:”==”classpath:/”,相对于根目录)

file: file:/com/xxx/beans.xml(使用UrlResource从文件系统目录中装载资源,绝对路径||相对路径)
http:// http://www.xxx.com/xxx/beans.xml(使用UrlResource从Web服务器中装载资源)
ftp:// ftp://www.xxx.com/xxx/beans.xml(使用UrlResource从FTP服务器中装载资源)

没有前缀 com/xxx/beans.xml(根据ApplicationContext具体实现类采用对应类型resource)

classpath*:匹配多个相同包名配置文件

classpath:匹配第一个相同包名配置文件

通配符

?:匹配文件名中的一个字符

*:匹配文件名中任意个字符

**:匹配多层路径
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: