You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring MVC-Hibernate集成应用运行时抛出XmlBeanDefinitionStoreException异常求助

解决Spring MVC-Hibernate集成中的XmlBeanDefinitionStoreException异常

先来看你遇到的具体异常:

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: ServletContext资源[/WEB-INF/spring/appServlet/servlet-context.xml]对应的XML文档第8行无效;嵌套异常为org.xml.sax.SAXParseException;lineNumber: 8; columnNumber: 107; cvc-elt.1.a: 无法找到元素'beans:beans'的声明。

这个问题的核心是XML Schema位置配置有语法错误,导致Spring无法正确加载对应的XSD约束文件,自然就识别不了beans:beans这个元素了。我仔细看了你贴的servlet-context.xml配置,发现两处明显的空格问题:

  1. 在beans的schema路径中,spring-和beans.xsd之间多了一个空格:
    错误写法:https://www.springframework.org/schema/beans/spring- beans.xsd
    正确写法:https://www.springframework.org/schema/beans/spring-beans.xsd

  2. 在tx的schema路径中,spring-tx-和4.0.xsd之间多了一个空格:
    错误写法:https://www.springframework.org/schema/tx/spring-tx- 4.0.xsd
    正确写法:https://www.springframework.org/schema/tx/spring-tx-4.0.xsd

修正后的完整命名空间配置

把你的XML头部替换成下面这段,我把schemaLocation拆成多行更易读,避免再出现空格错误:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="https://www.springframework.org/schema/mvc" 
             xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" 
             xmlns:beans="https://www.springframework.org/schema/beans" 
             xmlns:context="https://www.springframework.org/schema/context" 
             xmlns:tx="https://www.springframework.org/schema/tx" 
             xsi:schemaLocation="https://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
                                 https://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
                                 https://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd
                                 https://www.springframework.org/schema/tx https://www.springframework.org/schema/tx/spring-tx-4.0.xsd">

额外排查建议

如果修正后还是有问题,可以检查这几点:

  • 确认项目中Spring相关依赖的版本和你指定的spring-tx-4.0.xsd版本匹配,版本不兼容也可能导致Schema解析失败
  • 检查所有命名空间的URL是否拼写正确,比如beans对应的命名空间https://www.springframework.org/schema/beans有没有写错
  • 如果你是在线加载XSD,确保服务器能正常访问Spring的Schema仓库;也可以把XSD文件下载到本地项目中,修改schemaLocation指向本地路径(比如classpath:/xsd/spring-beans.xsd)

内容的提问来源于stack exchange,提问作者Srinath Murugula

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 09:19:10