转The content of element type "configuration" must match "(properties?,settings?,typ
Posted ZZZZW
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了转The content of element type "configuration" must match "(properties?,settings?,typ相关的知识,希望对你有一定的参考价值。
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-config.dtd">
- <!-- 注意:每个标签必须按顺序写,不然蛋疼的DTD会提示错误:The content of element type "configuration" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,plugins?,environments?,mappers?)". -->
- <configuration>
- <!-- 属性配置 -->
- <properties resource="com/mybatisdemo/config/mysql-jdbc-connection.properties">
- <!-- 相同属性:最高优先级的属性是那些作为方法参数的,然后是资源/url 属性,最后是 properties元素中指定的属性 -->
- <property name="username" value="root"/>
- <property name="password" value="sa"/>
- </properties>
- <!-- 设置缓存和延迟加载等等重要的运行时的行为方式 -->
- <settings>
- <!-- 设置超时时间,它决定驱动等待一个数据库响应的时间 -->
- <setting name="defaultStatementTimeout" value="25000"/>
- </settings>
- <!-- 别名 -->
- <typeAliases>
- <typeAlias alias="UserInfo" type="com.mybatisdemo.entity.UserInfo"/>
- </typeAliases>
- <environments default="development">
- <!-- environment 元素体中包含对事务管理和连接池的环境配置 -->
- <environment id="development">
- <transactionManager type="JDBC" />
- <!-- type分三种:
- UNPOOLED是每次被请求时简单打开和关闭连接
- UNPOOLED的数据源仅仅用来配置以下 4 种属性driver,url,username,password
- POOLED :JDBC连接对象的数据源连接池的实现,不直接支持第三方数据库连接池
- -->
- <dataSource type="POOLED">
- <property name="driver" value="${driver}" />
- <property name="url" value="${url}" />
- <property name="username" value="${username}" />
- <property name="password" value="${password}" />
- </dataSource>
- </environment>
- </environments>
- <!-- ORM映射文件 -->
- <mappers>
- <mapper resource="com/mybatisdemo/entity/config/UserInfoSqlMap.xml" />
- </mappers>
- </configuration>
注意:
①xml中的标签顺序不能随便调换,否则会提示错误
②MyBatis使用自带的数据库连接池,不直接支持第三方连接池,不过网上有创建第三方连接池的方法
③以前别名(<typeAliases>)可以在sqlMap标签中创建,但现在需要在configuration标签中创建
④该配置文件可随意取名,在读取配置文件时指定该XML文件路径即可:
- //读取核心配置文件
- Reader reader = Resources.getResourceAsReader("com/mybatisdemo/config/Configuration.xml");
- //创建SessionFactory实例
- SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
以上是关于转The content of element type "configuration" must match "(properties?,settings?,typ的主要内容,如果未能解决你的问题,请参考以下文章
MyBaties 错误The content of elements must consist of well-formed character data or markup.
mybatis报:The content of element type must match xx
Cause: org.xml.sax.SAXParseException: The content of elements must consist of well-formed character
hibernate配置文件 The content of element type "class" must match
Mybatis 异常: The content of elements must consist of well-formed character data or markup
The content of element type "configuration" must match "(properties?,settings?,typeAl