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

來源:互聯網
上載者:User

標籤:

【轉】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.   
  5. <!-- 注意:每個標籤必須按順序寫,不然蛋疼的DTD會提示錯誤:The content of element type "configuration" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,plugins?,environments?,mappers?)". -->  
  6. <configuration>  
  7.     <!-- 屬性配置 -->  
  8.     <properties resource="com/mybatisdemo/config/mysql-jdbc-connection.properties">  
  9.         <!-- 相同屬性:最高優先順序的屬性是那些作為方法參數的,然後是資源/url 屬性,最後是 properties元素中指定的屬性 -->  
  10.         <property name="username" value="root"/>  
  11.         <property name="password" value="sa"/>  
  12.     </properties>  
  13.       
  14.     <!-- 設定緩衝和消極式載入等等重要的運行時的行為方式 -->  
  15.     <settings>  
  16.         <!-- 設定逾時時間,它決定驅動等待一個資料庫響應的時間  -->  
  17.         <setting name="defaultStatementTimeout" value="25000"/>  
  18.     </settings>  
  19.       
  20.     <!-- 別名 -->  
  21.     <typeAliases>  
  22.         <typeAlias alias="UserInfo" type="com.mybatisdemo.entity.UserInfo"/>  
  23.     </typeAliases>  
  24.       
  25.     <environments default="development">  
  26.         <!-- environment 元素體中包含對交易管理和串連池的環境配置 -->  
  27.         <environment id="development">  
  28.             <transactionManager type="JDBC" />  
  29.             <!-- type分三種:  
  30.                     UNPOOLED是每次被請求時簡單開啟和關閉串連   
  31.                     UNPOOLED的資料來源僅僅用來配置以下 4 種屬性driver,url,username,password  
  32.                     POOLED :JDBC連線物件的資料來源串連池的實現,不直接支援第三方資料庫連接池  
  33.             -->  
  34.             <dataSource type="POOLED">  
  35.                 <property name="driver" value="${driver}" />  
  36.                 <property name="url" value="${url}" />  
  37.                 <property name="username" value="${username}" />  
  38.                 <property name="password" value="${password}" />  
  39.             </dataSource>  
  40.         </environment>  
  41.     </environments>  
  42.       
  43.     <!-- ORM對應檔 -->  
  44.     <mappers>  
  45.         <mapper resource="com/mybatisdemo/entity/config/UserInfoSqlMap.xml" />  
  46.     </mappers>  
  47.       
  48.       
  49. </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);  

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.