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

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


使用xml 配置spring. 启动程序时突然抛出: 文档根元素 “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 文件后正常运行.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值