您好,欢迎来到爱站旅游。
搜索
您的当前位置:首页一次马虎导致的异常: 文档根元素 "beans" 必须匹配 DOCTYPE 根 "null"

一次马虎导致的异常: 文档根元素 "beans" 必须匹配 DOCTYPE 根 "null"

来源:爱站旅游

  • spring 版本依赖问题.
  • beans 元素没有终止元素. 看xml 配置.

从下面的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:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="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
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd
">
    <context:property-placeholder location="classpath:application.xml"/>
    <context:component-scan base-package="cn.sheing.pead.chap12.connleak"/>
    <bean class="org.apache.commons.dbcp.BasicDataSource" id="dataSource"
          p:driverClassName="${database.driverName}"
          p:url="${database.url}"
          p:username="${database.username}"
          p:password="${database.password}"
          destroy-method="close"
    />

    <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
          id="transactionManager"
          p:dataSource-ref="dataSource"/>

    <bean class="org.springframework.jdbc.core.JdbcTemplate" id="jdbcTemplate"
    p:dataSource-ref="dataSource"/>

    <tx:annotation-driven transaction-manager="transactionManager"/>

</beans>

一个一个排除试试

  • 如果把beans 中所有元素都注释掉. spring 抛出org.springframework.beans.factory.NoSuchBeanDefinitionException 异常.
  • 一个一个元素注释掉.
    • <context:property-placeholde/> 注释掉后抛出 Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '${database.driverName}'
    • <context:component-scan/> 元素注释掉后抛出 文档根元素 “beans” 必须匹配 DOCTYPE 根 “null”。

应该是最后面的原因. 原来<context:property-placehole locatio=""/> 的值配置错了. location 修改为指定的properties 文件后正常运行.

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- azee.cn 版权所有 赣ICP备2024042794号-5

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务