ContextLoaderListener配置

    xiaoxiao2025-10-15  4

    在启动 Web 容器时,自动装配 Spring applicationContext.xml 的配置信息。

    因为它实现了ServletContextListener这个接口,在web.xml 配置这个监听器,启动容器时,就会默认执行它实现的方法。在ContextLoaderListener 中关联了ContextLoader 这个类,所以整个加载配置过程由ContextLoader 来完成。如果使用了 Log4jConfigListener,ContextLoaderListener在web.xml中配置在  Log4jConfigListener之后。

    默认情况下:如果在web.xml中不写任何参数配置信息,默认的路径是/WEB-INF/applicationContext.xml,在WEB-INF目录下创建的xml文件的名称必须是applicationContext.xml;

    配置指定路径:放在classpath下;配置信息如下:

    contextConfigLocation classpath:cpicgxwx-servlet-context.xml org.springframework.web.context.ContextLoaderListener

    在<param-value> </param-value>里指定相应的xml文件名,如果有多个xml文件,可以写在一起并一“,”号分隔。

       
    转载请注明原文地址: https://ju.6miu.com/read-1303173.html
    最新回复(0)