【问题标题】:Spring servlet in web.xml with missing contextConfigLocation param-valueweb.xml 中的 Spring servlet 缺少 contextConfigLocation 参数值
【发布时间】:2014-02-26 07:50:52
【问题描述】:

我有一个 web.xml 文件,其中包含(除其他外)一个定义 init-param 以指定 contextConfigLocation 的 servlet,但是 param-valueBLANK 吗?

开发人员为什么要这样做。我一生都无法在 Spring 3.X 的文档中找到任何能告诉我这有什么影响的东西。

<servlet>
    <servlet-name>restservices</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

【问题讨论】:

    标签: spring-mvc


    【解决方案1】:

    默认情况下,DispatcherServlet 将加载一个名为 [servlet-name]-servlet.xml 的 xml 文件。

    这是在没有定义名为 contextConfigLocationinit-param 时。

    但是,在您的情况下,定义了一个名为contextConfigLocationinit-param,它告诉DispatcherServlet 什么都不加载,而只委托给父上下文(由ContextLoaderListener 加载的那个)。

    简而言之,没有定义init-param 或空init-param 是有区别的。

    另见https://jira.springsource.org/browse/SPR-4746

    【讨论】:

      【解决方案2】:

      啊。一般来说,dispatcher servlet 会遵循搜索servlet-name - servlet.xml 来加载WebAppContext 的约定。 可能是(这只是猜测,因为我不知道你的配置)已经有一个文件restservices-servlet.xml,它是

      • 使用ContextLoaderListener加载
      • 或导入到您的applicationContext.xml(或其等效项)中
      • 或者不需要,因为 Controller/ViewResolver 的所有 bean 在您的applicationContext.xml 中配置

      通常,DispatcherServlet 配置 (WebappContext) 应包含 Controller/ViewResolver bean 定义。

      【讨论】:

        【解决方案3】:

        这只是因为开发人员在 servlet 配置中没有要声明的内容。 他可能已经在根上下文中定义了他需要的所有内容。

        【讨论】:

        • 那为什么还要包含 呢?
        • 我想没必要,然后尝试删除它
        猜你喜欢
        • 2015-02-16
        • 2016-12-18
        • 1970-01-01
        • 1970-01-01
        • 2012-05-08
        • 1970-01-01
        • 2018-03-29
        • 2012-03-20
        相关资源
        最近更新 更多