OFBiz 開發需要用到的幾個重要(配置)文件

摘要: OFBiz有很多的配置文件,知道這些配置文件和意義對於OFBiz開發非常重要。


OFBiz是一個非常好的企業級開發框架,實現了多層的鬆耦合結構,其中一部分鬆耦合就是通過配置文件實現的,這裏就要提到一些配置文件和開發文件。

1、首先是entityengine.xml文件,這個文件是配置數據源的,也包括數據庫連接池、事務實現類的配置和字段類型配置文件。企業級系統的開發一般都離不開數據庫,那麼在OFBiz中,數據庫的配置就在這個配置文件裏面,先配置一個group-map,然後配置其對應的數據源:

[html] view plaincopy
  1. Code highlighting produced by Actipro CodeHighlighter (freeware)  
  2. http://www.CodeHighlighter.com/  
  3.   
  4. --><delegator name="default" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main"   
  5.    distributed-cache-clear-enabled="false">  
  6.         <group-map group-name="org.ofbiz" datasource-name="ofbiz"/>  
  7.         <group-map group-name="com.aicent" datasource-name="portal"/>  
  8.     </delegator>  
  9.   
  10.     <datasource name="ofbiz"  
  11.             helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"  
  12.             field-type-name="mysql"  
  13.             check-on-start="false"  
  14.             add-missing-on-start="false"  
  15.             check-pks-on-start="false"  
  16.             use-foreign-keys="true"  
  17.             join-style="ansi-no-parenthesis"  
  18.             alias-view-columns="false"  
  19.             drop-fk-use-foreign-key-keyword="true"  
  20.             table-type="InnoDB"   
  21.             character-set="latin1"  
  22.             collate="latin1_swedish_ci">  
  23.         <read-data reader-name="seed"/>  
  24.         <read-data reader-name="seed-initial"/>  
  25.         <read-data reader-name="demo"/>  
  26.         <read-data reader-name="ext"/>  
  27.         <inline-jdbc  
  28.                 jdbc-driver="com.mysql.jdbc.Driver"  
  29.         jdbc-uri="jdbc:mysql://localhost/ofbiztrunk"  
  30.                 jdbc-username="root"  
  31.                 jdbc-password="123456"  
  32.                 isolation-level="ReadCommitted"  
  33.                 pool-minsize="2"  
  34.                 pool-maxsize="20"/>  
  35.         <!-- <jndi-jdbc jndi-server-name="localjndi" jndi-name="java:/MySqlDataSource" isolation-level="Serializable"/> -->  
  36.     </datasource>  
datasource配置裏面有一個field-type-name="mysql",到entitymodel.xml配置文件就知道是幹嗎用的了。

2.entitymodel.xml & entitygroup.xml
  OFBiz本質上來說還是面向數據庫的設計,entitymodel.xml的配置entity的,entity實體對應數據庫裏面的table,實體的field對應數據庫裏面的字段,如下是一個entity配置:

[html] view plaincopy
  1. Code highlighting produced by Actipro CodeHighlighter (freeware)  
  2. http://www.CodeHighlighter.com/  
  3.   
  4. --><entity entity-name="Customerinfo" package-name="com.aicent.ccb" no-auto-stamp="true"  
  5.         title="customerinfo">  
  6.         <field name="id" type="int10" ></field>  
  7.         <field name="name" type="varchar128"></field>  
  8.         <field name="customernameshort" type="varchar16"></field>  
  9.         <field name="country" type="varchar64"></field>  
  10.         <field name="businessaddr" type="text"></field>  
  11.         <field name="mailaddr" type="text"></field>  
  12.         <field name="billaddr" type="text"></field>  
  13.         <field name="phone" type="varchar32"></field>  
  14.         <field name="fax" type="varchar32"></field>  
  15.         <field name="website" type="varchar128"></field>  
  16.         <field name="note" type="text"></field>  
  17. </entity>  

裏面有一個type,這個type對應數據庫字段的類型(日期型,字符串型,整型等),這個對於關係在哪裏呢?就在剛纔說的field-type-name裏面配置,如果配置爲mysql,那麼entitygengine.xml中mysql的
field-type指向的文件是:
[html] view plaincopy
  1. Code highlighting produced by Actipro CodeHighlighter (freeware)  
  2. http://www.CodeHighlighter.com/  
  3.   
  4. --><field-type name="mysql" loader="fieldfile" location="fieldtypemysql.xml"/>  


在fieldtypemysql.xml中,就可以找到如int10,varchar128表示的實際mysql字段類型了:

[html] view plaincopy
  1. Code highlighting produced by Actipro CodeHighlighter (freeware)  
  2. http://www.CodeHighlighter.com/  
  3.   
  4. --> <fieldtypemodel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  5.         xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/fieldtypemodel.xsd">  
  6.     <!-- ===================== field-type-def ==================== -->  
  7.     <!-- General Types -->   
  8.      <field-type-def type="blob" sql-type="BLOB" java-type="java.sql.Blob"></field-type-def>  
  9.        
  10.      <field-type-def type="date-time" sql-type="DATETIME" java-type="java.sql.Timestamp"></field-type-def>  
  11.      <field-type-def type="date" sql-type="DATE" java-type="java.sql.Date"></field-type-def>  
  12.      <field-type-def type="time" sql-type="TIME" java-type="java.sql.Time"></field-type-def>  
  13.        
  14.      <field-type-def type="currency-amount" sql-type="DECIMAL(18,2)" java-type="java.math.BigDecimal"><validate method="isSignedDouble" /></field-type-def>  
  15.      <field-type-def type="currency-precise" sql-type="DECIMAL(18,3)" java-type="java.math.BigDecimal"><validate method="isSignedDouble" /></field-type-def>  
  16.      <field-type-def type="fixed-point" sql-type="DECIMAL(18,6)" java-type="java.math.BigDecimal"><validate method="isSignedDouble" /></field-type-def>  
  17.      <field-type-def type="floating-point" sql-type="DECIMAL(18,6)" java-type="Double"><validate method="isSignedDouble" /></field-type-def>  
  18.      <field-type-def type="numeric" sql-type="DECIMAL(20,0)" java-type="Long"><validate method="isSignedLong" /></field-type-def>  
  19.      <field-type-def type="integer" sql-type="INTEGER" java-type="Integer"></field-type-def>  
  20.        
  21.      <field-type-def type="id" sql-type="VARCHAR(20)" java-type="String"></field-type-def>  
  22.      <field-type-def type="id-long" sql-type="VARCHAR(60)" java-type="String"></field-type-def>  
  23.      <field-type-def type="id-vlong" sql-type="VARCHAR(250)" java-type="String"></field-type-def>  
  24.        
  25.      <field-type-def type="indicator" sql-type="CHAR(1)" java-type="String"></field-type-def>  
  26.      <field-type-def type="very-short" sql-type="VARCHAR(10)" java-type="String"></field-type-def>  
  27.      <field-type-def type="short-varchar" sql-type="VARCHAR(60)" java-type="String"></field-type-def>  
  28.      <field-type-def type="long-varchar" sql-type="VARCHAR(255)" java-type="String"></field-type-def>  
  29.      <field-type-def type="very-long" sql-type="LONGTEXT" java-type="String"></field-type-def>  
  30.       
  31.      <field-type-def type="comment" sql-type="VARCHAR(255)" java-type="String"></field-type-def>  
  32.      <field-type-def type="description" sql-type="VARCHAR(255)" java-type="String"></field-type-def>  
  33.      <field-type-def type="name" sql-type="VARCHAR(100)" java-type="String"></field-type-def>  
  34.      <field-type-def type="value" sql-type="VARCHAR(255)" java-type="String"></field-type-def>  
  35.        
  36.      <!-- customize field type definitions for ccb -->  
  37.      <field-type-def type="text" sql-type="TEXT" java-type="String"></field-type-def>  
  38.        
  39.      <field-type-def type="char" sql-type="CHAR(1)" java-type="String"></field-type-def>  
  40.      <field-type-def type="char125" sql-type="CHAR(125)" java-type="String"></field-type-def>  
  41.      <field-type-def type="varchar16" sql-type="VARCHAR(16)" java-type="String"></field-type-def>  
  42.      <field-type-def type="varchar20" sql-type="VARCHAR(20)" java-type="String"></field-type-def>  
  43.      <field-type-def type="varchar24" sql-type="VARCHAR(24)" java-type="String"></field-type-def>  
  44.      <field-type-def type="varchar50" sql-type="VARCHAR(50)" java-type="String"></field-type-def>  
  45.      <field-type-def type="varchar64" sql-type="VARCHAR(64)" java-type="String"></field-type-def>  
  46.      <field-type-def type="varchar128" sql-type="VARCHAR(128)" java-type="String"></field-type-def>  
  47. </fieldtypemodel>  

OFBiz這裏爲什麼不在entitymodel裏面直接使用字段在數據庫中的類型,而這麼繞呢?我想至少有兩個目的:首先是公司企業開發時可以針對使用的字段類型有一個規範,所有的字段都採用這個配置文件中的字段類型,而不是開發人員自己隨意定義數據庫字段的類型;第二是爲了使用不同Vendor的數據庫,如果想從mysql換成oracle,只需要定義另一份fieldtypeoracle.xml,field-type-def中sql-type不變,而sql-tye換成oracle的類型即可。

entitygroup.xml配置文件時用於配置entitymodel.xml中配置的entity是屬於哪個group的,這個group對應entityengine.xml中的group-name,如果忘記在entitygroup.xml中配置,那麼在OFBiz 9之前,這個entity就無法使用,不會創建相應的table,OFBiz 9以後,默認的group name是org.ofbiz。
[html] view plaincopy
  1. Code highlighting produced by Actipro CodeHighlighter (freeware)  
  2. http://www.CodeHighlighter.com/  
  3.   
  4. --><entitygroup xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.         xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/entitygroup.xsd">  
  6.   
  7.   
  8.     <entity-group group="com.aicent" entity="Customerextra" />  
  9.     <entity-group group="com.aicent" entity="Customerinfo" />  
  10.   
  11. </entitygroup>  

3.ofbiz-containers.xml 裏面配置了各種容器類,經常修改的容器就是name爲catalina-container的容器,使用的是embeded tomcat,裏面可以修改各種tomcat的配置項,就像我們修改tomcat的配置文件server.xml一樣,在裏面修改端口等信息。

4.log4j.xml 日誌配置文件

5.component-load.xml 這個文件在幾個文件夾中都存在,如framework,applications,specialpurpose中。OFBiz將一個個應用實現爲component,這些componnet是就好像tomcat中webapps中的一個個web應用。每次是否加載這個component可以在component-load.xml配置,如果不想加載,註釋掉就可以。

[html] view plaincopy
  1. Code highlighting produced by Actipro CodeHighlighter (freeware)  
  2. http://www.CodeHighlighter.com/  
  3.   
  4. --><component-loader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  5.         xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/component-loader.xsd">  
  6.     <load-component component-location="commonext"/><!-- common component used by most other components -->       
  7.     <load-component component-location="securityext"/>  
  8.     <!--  
  9.     <load-component component-location="party"/>  
  10.     <load-component component-location="content"/>  
  11.     <load-component component-location="workeffort"/>  
  12.     <load-component component-location="product"/>  
  13.     <load-component component-location="manufacturing"/>  
  14.     <load-component component-location="accounting"/>  
  15.     <load-component component-location="humanres"/>  
  16.     <load-component component-location="order"/>  
  17.     <load-component component-location="marketing"/>  
  18.     -->  
  19. </component-loader>  


到底哪些目錄下的component-load.xml有效呢,這個目錄在framework/base/config/component-load.xml進進行配置:

[html] view plaincopy
  1. Code highlighting produced by Actipro CodeHighlighter (freeware)  
  2. http://www.CodeHighlighter.com/  
  3.   
  4. --><component-loader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  5.         xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/component-loader.xsd">  
  6.     <load-components parent-directory="framework"/>   
  7.     <load-components parent-directory="themes"/>   
  8.     <load-components parent-directory="applications"/>  
  9.     <load-components parent-directory="specialpurpose"/>  
  10.     <load-components parent-directory="hot-deploy"/>  
  11. </component-loader>  

6.general.properties 這裏面配置的東西很多,大家自己去看吧。

7.cache.properties 配置OFBiz中的緩存,配置這個文件需要對OFBiz中的緩存有所瞭解,這個在後續文章中進行分析。

其他還有一些比較配置的文件,就不一一說明了
發佈了9 篇原創文章 · 獲贊 6 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章