【问题标题】:What is correct path什么是正确的路径
【发布时间】:2015-05-02 10:40:46
【问题描述】:

从 web xml 到我的 hhconfig.xml 的正确路径是什么?

<context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:/hhconfig.xml</param-value>
</context-param>

<listener>
   <listener-class>
      org.springframework.web.context.ContextLoaderListener
   </listener-class>
</listener>

    <!-- Processes application requests -->
    <servlet>
      <servlet-name>hhconfig</servlet-name>
      <servlet-class>
         org.springframework.web.servlet.DispatcherServlet
      </servlet-class>
      <load-on-startup>1</load-on-startup>
   </servlet>

   <servlet-mapping>
      <servlet-name>hhconfig</servlet-name>
     <url-pattern>/</url-pattern>
   </servlet-mapping>

</web-app>

这是我在项目树中的屏幕

http://zapodaj.net/22e3adc3a776f.png.html

【问题讨论】:

  • 您可以将hhconfig.xml 文件添加到src/main/resources 包中并更改参数值classpath:hhconfig.xml 而不是classpath:/hhconfig.xml。
  • 然后我有 :ERROR: org.springframework.web.servlet.DispatcherServlet - 上下文初始化失败 org.springframework.beans.factory.BeanDefinitionStoreException: IOException 从 ServletContext 资源解析 XML 文档 [/WEB-INF/ hhconfig-servlet.xml];嵌套异常是 java.io.FileNotFoundException: 无法打开 ServletContext 资源 [/WEB-INF/hhconfig-servlet.xml]
  • 您可以将您的xml文件名hhconfig.xml更改为hhconfig-servlet.xml。我不确定,但我认为这对你有帮助。

标签: java spring jakarta-ee


【解决方案1】:

您的hhconfig.xml 必须直接位于src/main/resources - 目前它位于src/main/resources/META-INF 下。 src/main/resources 中的所有文件都将添加到 &lt;war&gt;/WEB-INF/classes,因此它们将在您的 Web 应用的类路径中可用。

您还需要将classpath:/hhconfig.xml 更改为classpath:hhconfig.xml。查看Spring documentation 获取资源字符串示例。

【讨论】:

    猜你喜欢
    • 2015-01-10
    • 1970-01-01
    • 2011-01-27
    • 2016-04-25
    • 1970-01-01
    • 2013-10-12
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多