【发布时间】: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>
这是我在项目树中的屏幕
【问题讨论】:
-
您可以将
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