spring进阶(一)之配置文件解析

1. spring 做junit测试时,需要从配置文件中创建ApplicationContext对象

     整合到web项目中时,通过配置ContextLoaderListener来装配ApplicationContext的配置信息。

     applictionContext的作用:

作用1:责读取bean配置文档,管理bean的加载,实例化,维护bean之间的依赖关系,负责bean的声明周期。
  作用2:提供更完整的框架功能:
   a. 国际化支持
   b. 资源访问:Resource rs = ctx. getResource(“classpath:config.properties”),“file:c:/config.properties”
   c. 事件传递:通过实现ApplicationContextAware接口

    contextLoaderListener的作用(web.xml中):

启动Web容器时,自动装配ApplicationContext的配置信息。
因为它实现了ServletContextListener这个接口,在web.xml配置这个监听器,启动容器时,就会默认执行它实现的方法。

contextLoaderListener一般配合contextConfigLocation一起使用,来加载spring配置文件,否则会默认查找/WEB-INF/applicationContext.xml路径下的配置文件。

---------至此spring在web.xml中的配置结束--------------------------------


2. 配置springmvc

      springmvc的核心控制器:DispatcherServlet

       contextConfigLocation配置文件路径

       配置拦截器


3.  配置乱码编码

     

<!-- 乱码解决 -->
	  <filter>  
	        <filter-name>characterEncodingFilter</filter-name>  
	        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
	        <init-param>  
	            <param-name>encoding</param-name>  
	            <param-value>UTF-8</param-value>  
	        </init-param>  
	        <init-param>  
	            <param-name>forceEncoding</param-name>  
	            <param-value>true</param-value>  
	        </init-param>  
	 </filter>  
	    <filter-mapping>  
	        <filter-name>characterEncodingFilter</filter-name>  
	        <url-pattern>/*</url-pattern>  
	    </filter-mapping>  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值