控制台向我抛出此错误
ERROR: org.springframework.web.servlet.DispatcherServlet - Context initialization failed
Line 23 in XML document from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml] is invalid
这是我的 servlet 上下文文件
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.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.xsd">
<annotation-driven />
<resources mapping="/resources/**" location="/resources/" />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
<context:component-scan base-package="mvc.test.hib" />
</beans:bean>
我缺少什么?我对 spring/hibernate 编程很陌生,有些事情我仍然不太理解
编辑:附加详细信息,我正在使用 Spring 工具套件和默认的 MVC spring 模板项目。
最佳答案
您发布的文件只有 21 行,而您给出的错误消息表明第 23 行无效。假设您在发布文件时丢失了几个换行符,那么您似乎缺少 <beans:beans>
的结束标记。声明。将以下内容添加到文件末尾,xml 语法将有效。
</beans:beans>
如果您使用 IDE(例如 Eclipse)或具有内置 XML 验证的文本编辑器(例如带有 XML 工具插件的 Notepad++),您会发现编写 XML 会更容易。这将使您更容易、更快地找到语法错误。
关于java - ServletContext 资源中的 XML 文档无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32079661/