Spring--ApplicationContext

2018-07-18  本文已影响0人  栗子酥小小

各种继承层级

BeanFactory 提供了最基本的IOC容器的功能,是IOC容器的基本形式,而各种ApplicationContext的实现是IOC容器的高级表现形式。

ApplicationContext 和 BeanFactory都能够获取getBean,区别在于:

ApplicationContext 的实现类

当然FileSystemXmlApplicationContext和ClassPathXmlApplicationContext都可以显式使用带资源类型(classpath:或file:)前缀的路径,它们的区别在于如果不显式指定资源类型前缀,将分别将路径解析为文件系统路径和类路径罢了。

WebApplicationContext

<!--①指定配置文件--> 
<context-param>                                                        
     <param-name>contextConfigLocation</param-name>   
     <param-value> 
       /WEB-INF/baobaotao-dao.xml, /WEB-INF/baobaotao-service.xml  
   </param-value> 
</context-param> 
<!--②声明Web容器监听器--> 
<listener>   
     <listener-class>org.springframework.web.context.ContextLoaderListener </listener-class> 
</listener> 
<context-param> 
     <param-name>contextConfigLocation</param-name>   
     <param-value>/WEB-INF/baobaotao-dao.xml, /WEB-INF/baobaotao-service.xml </param-value> 
</context-param> 
…  
<!--①声明自动启动的Servlet --> 
<servlet>   
    <servlet-name>springContextLoaderServlet</servlet-name> 
    <servlet-class>org.springframework.web.context.ContextLoaderServlet </servlet-class> 
    <!--②启动顺序--> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<context-param> 
        <param-name>contextConfigLocation</param-name> 
        <param-value> 
           /WEB-INF/baobaotao-dao.xml,/WEB-INF/baobaotao-service.xml  
        </param-value> 
    </context-param> 
     <!--①指定Log4J配置文件位置--> 
    <context-param>                                             
        <param-name>log4jConfigLocation</param-name> 
        <param-value>/WEB-INF/log4j.properties</param-value> 
    </context-param> 
 
    <!--②装载Log4J配置文件的自启动Servlet --> 
    <servlet> 
        <servlet-name>log4jConfigServlet</servlet-name> 
        <servlet-class>org.springframework.web.util.Log4jConfigServlet</servlet-class> 
        <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet> 
        <servlet-name> springContextLoaderServlet</servlet-name> 
        <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class> 
    <load-on-startup>2</load-on-startup> 
</servlet> 
上一篇下一篇

猜你喜欢

热点阅读