首页 > 其他分享 >Spring—Document root element "beans", must match DOCTYPE root "null"分析及解决方法

Spring—Document root element "beans", must match DOCTYPE root "null"分析及解决方法

时间:2023-09-07 14:35:28浏览次数:37  
标签:xml Spring DOCTYPE DTD beans spring null root


Document root element "beans", must match DOCTYPE root "null".的错误提示,网上很多人说要把applicationContex.xml文件中加上如下第二行的

<!DOCTYPE/>标签,说明DTD,其实并不准确。 

 <?xml version="1.0" encoding="UTF-8"?> 

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans>
 ……
 </beans>
 实例中的配置文件时beans-config.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"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">       
     <bean id="helloBean"
           class="onlyfun.caterpillar.HelloBean">
         <property name="helloWord">
             <value>Hello!Justin!</value>
         </property>
     </bean>
 </beans>
 很显然这是XML Schema的设置方式。我把它改为XML DTD的设置方式,如下:
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
 "http://www.springframework.org/dtd/spring-beans.dtd">
  <beans>     
     <bean id="helloBean"
           class="onlyfun.caterpillar.HelloBean">
         <property name="helloWord">
             <value>Hello!Justin!</value>
         </property>
     </bean>
 </beans>


再次运行,OK,成功!后来在spring forum上发现了正解:
You have the wrong xml configuration for the version of spring.

1.x use DOCTYPE
2.x use schema

You must have 1.x in the classpath.
引自http://forum.springframework.org/showthread.php?t=37883

    现在明白了,spring 1.x 使用DOCTYPE,而2.x是用schema,我的项目出错原因是由于前面的其他错误怀疑spring版本问题把spring2.0换成了spring1.2,而我使用的Spring IDE是以前配置的Spring1.x版本。改用配置文件为XML DTD解析方式就可以了,或者更新Spring IDE为2.x版本也可以解决问题。
 

标签:xml,Spring,DOCTYPE,DTD,beans,spring,null,root
From: https://blog.51cto.com/u_2544485/7396969

相关文章

  • buildroot 构建根文件系统(6)添加字体和中文支持
    一、开发背景构建最小系统后成功运行后,Qt程序在界面上文本不显示二、开发需求Qt库编译的程序可以正常运行三、开发环境LinuxUbuntu4.15.0-65-generic+buildroot-2023.02.3+i.mx6d(cortex-A9)四、实现步骤1、添加界面中文支持1)基于前面章......
  • springboot打包运行失败
    没有包含启动类的class添加mavenpom.xml;`org.springframework.bootspring-boot-maven-plugin${spring-boot.version}com.hidisp.HidispApplication<!--issue:SpringBoot-0.0.1-SNAPSHOT.jar中没有主清单属性 resolve:①注释掉,或者②将skip值改为......
  • Spring源码分析(十)Spring中Bean的生命周期(下)
    在上篇文章中,写了bean的生命周期的简单介绍,主要介绍了整个生命周期中的初始化阶段以及基于容器启动停止时LifeCycleBean的回调机制。另外对bean的销毁过程也做了简单介绍,但是对于整个bean的生命周期,这还只是一小部分,在这篇文章中,我将继续完成剩下部分的内容,同时对之前的内容做一次......
  • Spring注入DAO之怪错
     spring配置:<beanname="searchKeywordDAO"class="com.miracle.dm.sdmgr.searchkeyword.dao.impl.SearchKeywordDAOImpl"><propertyname="sqlMapClient"ref="sqlMapClient"/></bean><......
  • springboot项目自动运行脚本
    注意文件格式unix格式(Windowscrlf换行符有不可见字符)#!/bin/sh#服务名(要与配置文件中的server名保持一致)APP_NAME=""#git本地仓库路径GIT_RESPOSITORY=""#配置文件存储位置PROFILE_LOCATION=""#配置文件名PROFILE_NAME=""#日志文件存储位置LOG_LOCATION="......
  • spring中的bean使用注解创建,applicationContext.xml中需要写的内容,以及dao,service实
    2023-09-07applicationContext.xml<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns......
  • springBoot long类型 长id 到前端丢失精度问题
    在SpringBoot中,如果将Long类型的id传递到前端,可能会遇到精度丢失的问题。这是因为JavaScript无法精确地表示大于Number.MAX_SAFE_INTEGER(即9007199254740991)的整数。为了解决这个问题,你可以采用以下方法之一:方式1:通过注解方式@Data@EqualsAndHashCode(callSuper=false)......
  • SpringBoot学习之配置MyBatis常见异常
    Invalidboundstatement(notfound)出现原因和解决方法: 常见原因:1.mapper.xml中namespace和实际mapper接口所在的位置不一致。2.mapper.xml中的id名称和maapper接口中的方法名称不一致。3.如果上述两点都没有问题,那么大概率是application配置文件有配置错误。 程序和S......
  • springmvc
    模型-视图-控制器的设计模式,将程序进行分层解耦springmvc执行流程(1)用户发送请求至前端控制器(DispatcherServlet)(2)DispatcherServlet收到请求后,调用HandlerMapping处理器映射器,请求获取Handle;(3)处理器映射器根据请求url找到具体的处理器,生成处理器对象及处理器拦截器(如果有则......
  • pringboot/springmvc 获取项目中的所有请求路径
    springboot/springmvc获取项目中的所有请求路径1.编写业务代码@Autowired privateWebApplicationContextapplicationContext;@GetMapping("/getAllURL") publicRestfulResultgetAllURL(){ //获取springmvc处理器映射器组件对象RequestMappingHandlerMappin......