gpt4 book ai didi

java - 嵌套异常是 java.io.FileNotFoundException : Could not open ServletContext resource [/spring/servlet-context. xml]

转载 作者:行者123 更新时间:2023-11-28 22:35:49 25 4
gpt4 key购买 nike

好的,感谢您帮助解决最后一个问题。这是我的新错误和随后的代码。错误中的粗体文本是我所关心的全部修复,因为这是唯一的错误。

[Thread-36] ContextLoader ERROR Context initialization failed org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/spring/servlet-context.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/spring/servlet-context.xml] at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:93) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4701) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5204) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5199) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/spring/servlet-context.xml] at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:117) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328) ... 19 more Oct 16, 2013 7:44:51 AM org.apache.catalina.core.StandardContext startInternal SEVERE: Error listenerStart Oct 16, 2013 7:44:51 AM org.apache.catalina.core.StandardContext startInternal SEVERE: Context [/mdimgmtsys-1.0-SNAPSHOT] startup failed due to previous errors

现在是代码:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">


<context-param>
<param-name>contextAppConfigLocation</param-name>
<param-value>app-context.xml classpath*:app-context.xml</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/spring/servlet-context.xml classpath*:servlet-context.xml</param-value>
</context-param>

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

<!-- Enables Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextAppConfigLocation</param-name>
<param-value>app-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>contextServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/spring/servlet-context.xml</param-value>

</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
<servlet-name>contextServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>

我所做的一切都无法在 Tomcat 中启动应用程序。

最佳答案

在 spring web 项目中,Application Context 和 Servlet Context 是有区别的。我们用来配置Application Context,用法和你的用法一样

<context-param>
<param-name>contextAppConfigLocation</param-name>
<param-value>classpath:app-context.xml</param-value>
</context-param>

对于 Servlet 上下文,默认 Web 容器将尝试在 WEB-INF 目录中查找#servlet-name#-servlet.xml,因此对于您的问题,您需要将您的移动到 WEB-INF 目录并更改其名称到相应的名称(contextServlet-servlet.xml,appServlet-servlet.xml)

关于java - 嵌套异常是 java.io.FileNotFoundException : Could not open ServletContext resource [/spring/servlet-context. xml],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19402671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com