Java Spring org.springframework.beans.factory.BeanDefinitionStoreException:IOException解析来自ServletContext资源的XML文档
当我在Glassfish 4/Tomcat 8上部署我的第一个Spring MVC应用程序时,我遇到了这个错误Java Spring org.springframework.beans.factory.BeanDefinitionStoreException:IOException解析来自ServletContext资源的XML文档,java,spring,spring-mvc,spring-framework-beans,Java,Spring,Spring Mvc,Spring Framework Beans,当我在Glassfish 4/Tomcat 8上部署我的第一个Spring MVC应用程序时,我遇到了这个错误 org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/myFirstSpring-servlet.xml]; nested exception is java.io.Fi
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/myFirstSpring-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/myFirstSpring-servlet.xml]
我认为我的Servlet配置有问题
web.xml
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>MyDemoApp</display-name>
<servlet>
<servlet-name>myFirstSpring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contexConfiguration</param-name>
<param-value>/WEB-INF/config/myDemoApp-servletConfig.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>myFirstSpring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
MyDemoApp
我的第一个春天
org.springframework.web.servlet.DispatcherServlet
上下文配置
/WEB-INF/config/myDemoApp-servletConfig.xml
我的第一个春天
*.html
我的SpringBean配置文件名为myDemoApp-servletConfig.xml
[![<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<mvc:annotation-driven></mvc:annotation-driven>
<context:component-scan base-package="com.demo.controllers"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="WEB=INF/jsp"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>][1]][1]
[[
][1]][1]
关于我做错了什么有什么线索吗
真诚地说,将myFirstSpring-servlet.xml放在您的WEB-INF文件夹中。
如果您执行了,但仍然无法工作,请清理项目并重试。我的配置servlet名为myDemoApp-servletConfig.xml。映射位于init params:contexConfiguration/WEB-INF/config/myDemoApp-servletConfig.xml中。在WEB.xml中声明ContextLoaderListener,并使用contextConfigLocation设置要加载的上下文文件。然后在init参数中将contextConfiguration更改为contextConfigLocation,并查看它是否有效。这里有一个要检查的链接:
contextConfiguration
不是contextConfiguration
。您在参数名称中输入了一个错误。