zoukankan      html  css  js  c++  java
  • The reference to entity "characterEncoding" must end with the ';'

    在配置数据库连接池数据源时,本来没有错误,结果加上编码转换格式后eclipse突然报错:

    这是怎么回事?

    经过查询,发现这个错误其实很好解决。

    首先,原因是: .xml文件中 ‘ & ’字符需要进行转义!!!

    看到这里,其实已经恍然大悟,那么,这个字符 ‘ & ’ 需要怎么转义呢?看下面这张表:

    在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:aop="http://www.springframework.org/schema/aop"
        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/aop
            http://www.springframework.org/schema/aop/spring-aop.xsd">
        <!-- 管理DataSource -->
        <bean id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <!-- set方法注入属性,和类中的成员属性无关,和set方法名称有关,比如有一个属性叫username,但是set方法:setName -->
            <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"></property>
            <!-- 转义前 -->
            <property name="url" value="jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai"></property>
            <!-- 转义后 -->
            <property name="url" value="jdbc:mysql://localhost:3306/demo?useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=Asia/Shanghai"></property>
            <property name="username" value="root"></property>
            <property name="password" value="root"></property>
        </bean>
        <!-- 管理jdbcTemplate -->
        <bean id="template"
            class="org.springframework.jdbc.core.JdbcTemplate">
            <constructor-arg name="dataSource" ref="dataSource"></constructor-arg>
        </bean>
    </beans>
  • 相关阅读:
    Xpath语法与lxml库的用法
    Selenium--使用参考
    PhantomJS的替代品--无头浏览器(Headless Chrome)
    为什么只有一个元素的tuple要加逗号?
    反爬利器--设置代理服务器
    LeetCode 221. 最大正方形 | Python
    LeetCode 572. 另一个树的子树 | Python
    LeetCode 98. 验证二叉搜索树 | Python
    LeetCode 45. 跳跃游戏 II | Python
    LeetCode 25. K 个一组翻转链表 | Python
  • 原文地址:https://www.cnblogs.com/chenyanbin/p/11839321.html
Copyright © 2011-2022 走看看