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

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</listener-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:匹配第一个相同包名配置文件

通配符
?:匹配文件名中的一个字符
*:匹配文件名中任意个字符
**:匹配多层路径

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值