【转】The content of element type "configuration" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?...

【转】The content of element type "configuration" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?...

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-config.dtd">
  4. <!-- 注意:每个标签必须按顺序写,不然蛋疼的DTD会提示错误:The content of element type "configuration" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,plugins?,environments?,mappers?)". -->
  5. <configuration>
  6. <!-- 属性配置 -->
  7. <properties resource="com/mybatisdemo/config/mysql-jdbc-connection.properties">
  8. <!-- 相同属性:最高优先级的属性是那些作为方法参数的,然后是资源/url 属性,最后是 properties元素中指定的属性 -->
  9. <property name="username" value="root"/>
  10. <property name="password" value="sa"/>
  11. </properties>
  12. <!-- 设置缓存和延迟加载等等重要的运行时的行为方式 -->
  13. <settings>
  14. <!-- 设置超时时间,它决定驱动等待一个数据库响应的时间  -->
  15. <setting name="defaultStatementTimeout" value="25000"/>
  16. </settings>
  17. <!-- 别名 -->
  18. <typeAliases>
  19. <typeAlias alias="UserInfo" type="com.mybatisdemo.entity.UserInfo"/>
  20. </typeAliases>
  21. <environments default="development">
  22. <!-- environment 元素体中包含对事务管理和连接池的环境配置 -->
  23. <environment id="development">
  24. <transactionManager type="JDBC" />
  25. <!-- type分三种:
  26. UNPOOLED是每次被请求时简单打开和关闭连接
  27. UNPOOLED的数据源仅仅用来配置以下 4 种属性driver,url,username,password
  28. POOLED :JDBC连接对象的数据源连接池的实现,不直接支持第三方数据库连接池
  29. -->
  30. <dataSource type="POOLED">
  31. <property name="driver" value="${driver}" />
  32. <property name="url" value="${url}" />
  33. <property name="username" value="${username}" />
  34. <property name="password" value="${password}" />
  35. </dataSource>
  36. </environment>
  37. </environments>
  38. <!-- ORM映射文件 -->
  39. <mappers>
  40. <mapper resource="com/mybatisdemo/entity/config/UserInfoSqlMap.xml" />
  41. </mappers>
  42. </configuration>

注意:

①xml中的标签顺序不能随便调换,否则会提示错误

②MyBatis使用自带的数据库连接池,不直接支持第三方连接池,不过网上有创建第三方连接池的方法

③以前别名(<typeAliases>)可以在sqlMap标签中创建,但现在需要在configuration标签中创建

④该配置文件可随意取名,在读取配置文件时指定该XML文件路径即可:

Java代码  

  1. //读取核心配置文件
  2. Reader reader = Resources.getResourceAsReader("com/mybatisdemo/config/Configuration.xml");
  3. //创建SessionFactory实例
  4. SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
时间: 2024-12-30 21:11:26

【转】The content of element type "configuration" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?...的相关文章

The content of element type &quot;configuration&quot; must match &quot;(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?...

今天在mybaties配置文件中碰到这样的一个问题:The content of element type "configuration" must match 解决如下:properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,plugins?,environments?,mappers? 按以上提示的顺序写标签.

【原创】mybatis配置文件报错:The content of element type &quot;configuration&quot; must match &quot;(properties&gt;settings&gt;typeAliases&gt;typeHa...

最近使用mybatis,在mybatis的xml配置文件中总是会提示错误 The content of element type "configuration" must match "(properties>settings>typeAliases>typeHandlers>objectFactory>objectWrapperFactory>plugins>environments>mappers?)". 后来发现

mybatis配置文件,注意标签配置顺序。否则报错The content of element type &quot;configuration&quot; must match &quot;(properties?,settings?,...怎么解决

感谢原作者http://www.cnblogs.com/zhoumingming/p/5417014.html 注意每个标签必须按照顺序写,不然就会提示错误 顺序是 <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd

The content of element type &quot;package&quot; must match &quot;(result-types?,interceptors?...

错误:“The content of element type "package" must match "(result-types?,interceptors?,default-interceptor-ref?,default-action-ref?,default-class-ref?,global-results?,global-exception-mappings?,action*)". ” 原因:package里元素必须按照一定的顺序排列: result

web.xml中&lt;web-app&gt;报错了--The content of element type &quot;web-app&quot; must match

web.xml中<web-app>报错了--The content of element type "web-app" must match.真是活见鬼! 查完资料后发现,原来web-app_2_3.dtd规范有规定,里面配置的内容要按照规定的顺序来,如下: (icon?,display-name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,se

hibernate配置文件 The content of element type &quot;class&quot; must match

hibernate映射文件hbm.xml出错,错误信息如下: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?, (version|timestamp)?,(property|many-to-one|one-to-one|comp

The content of element type &quot;context&quot; must match &quot;(property*,plugin*,commentGenerator?

最近项目用SSM框架,在利用mybatis generator反向生成数据库对应的model实体时,报如下错误: The content of element type "context" must match "(property*,plugin*,commentGenerator?,jdbcConnection,javaTypeResolver?,javaModelGenerator,sqlMapGenerator?,javaClientGenerator?,table+

The content of element type &quot;beans&quot; must match &quot;(description?,(import|alias|bean)*)

The content of element type "beans" must match "(description?,(import|alias|bean)*) ------------------------------------------------- 解决方案: 版本问题,xml修改成这样就可以了,亲测 <?xml version="1.0" encoding="UTF-8" ?> <!-- 必须配置一

web.xml中&lt;web-app&gt;提示The content of element type &quot;web-app&quot; must match &quot;(icon?,display- name?,description?,distributable?,

错误:配置web.xml时,出现红色叉叉,提示 The content of element type "web-app" must match "(icon?,display-  name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-  mapping*,session-config?,mime-mapping*,welcome-