• Document root element "beans", must match DOCTYPE root "null".


    新建一个maven项目  引用spring时新建一个测试类

    application.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.xsd">
    <bean id="user" class="com.wenxin.www.domain.user">
    <property name="name" value="0001">
    </property>
    </bean>
    </beans>

    因为对框架不是很了解 所以配置方法都是网上查找的

    测试类如下

    public class Test {
    public static void main(String[] args) {
    String location="classpath:applicationContext.xml";
    ApplicationContext ctx=new ClassPathXmlApplicationContext(location);
    user cous=(user)ctx.getBean("user");
    System.out.println(cous.getName());
    }
    }

    运行后报错  

     主要原因是因为 application.xml  配置有问题

    我的配置是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="user" class="com.wenxin.www.domain.user">
    <property name="name" value="wangli">
    </property>
    </bean>
    </beans>

    再次运行,就成功了

    主要原因是我引用的     spring 是  1.x  应该用 DOCTYPE    如果是  2.x  就要用 schema

  • 相关阅读:
    KVM使用入门
    虚拟化技术之KVM
    MySQL初始化以及客户端工具的使用
    Python基础数据类型-字典(dict)
    Golang异常处理-panic与recover
    HTML&CSS基础-overflow
    MySQL数据类型以及基本使用详解
    HTML&CSS基础-display和visibility
    golang数据传输格式-序列化与反序列化
    Golang的文件处理方式-常见的读写姿势
  • 原文地址:https://www.cnblogs.com/zjf6666/p/9055074.html
Copyright © 2020-2023  润新知