我在 web.xml 中定义了以下内容
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:p360UiSpringConfig/p360UiDispatcherServlet-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>p360UiDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
下面是我的 web-inf 的样子:
当我在 WebLogic 中启动应用程序时,出现以下错误:
错误java.io.FileNotFoundException:无法打开ServletContext资源[/WEB-INF/p360UiDispatcherServlet-servlet.xml]
问题是当我定义了 contextConfigLocation 后,为什么它要在 Web-Inf 中寻找 spring 配置文件?
最佳答案
编辑您的 contextConfigLocation
在 web.xml
如下。
编辑
发生的事情是 Spring 容器正在尝试通过 <Dispatcher Servlet Name>-servlet.xml
寻找上下文在 WEB-INF 文件夹中。这是因为您没有指定 <init-param>
对于调度程序 servlet p360UiDispatcherServlet
。 <context-param>
用于指定常见的附加上下文路径,例如 DAO、安全性等。这应该可以理想地解决您的问题。请查看修改后web.xml
<!-- Any Common Additional Context Paths -->
<!--<context-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</context-param>-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>p360UiDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/p360UiSpringConfig/p360UiDispatcherServlet-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
关于java - WebLogic 启动应用程序失败 - 找不到 spring 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24856353/