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>
  • 相关阅读:
    numpy函数:[6]arange()详解
    python中的list和array的不同之处
    python 矩阵转置transpose
    PowerDesigner(一)-PowerDesigner概述(系统分析与建模)
    MDX中Filter 与Exist的区别
    SQL Server 2016 —— 聚集列存储索引的功能增强
    SQL Server 2016:内存列存储索引
    PXE
    setjmp
    skb head/data/tail/end/介绍
  • 原文地址:https://www.cnblogs.com/chenyanbin/p/11839321.html
Copyright © 2011-2022 走看看