139
技術社區[雲棲]
PropertySet教程-1.簡介和配置
inkfish原創,請勿商業性質轉載,轉載請注明來源(https://blog.csdn.net/inkfish )。
PropertySet(來源:https://blog.csdn.net/inkfish) 是由opensymphony組織開發的的一個開源項目,但是那個項目文檔少,長時間沒有更新,官方文檔錯誤奇多,所以現在在項目中使用並不廣泛。但這並不妨礙PropertySet成為一個優秀的key-value持久化模塊,當前,PropertySet可以說已經夠用。這裏我整理書寫了PropertySet的文檔。(來源:https://blog.csdn.net/inkfish)
Property文檔 (來源:https://blog.csdn.net/inkfish)
Property簡介(來源:https://blog.csdn.net/inkfish)
簡而言之,PropertySet就是一個存儲key-value對的模塊,他能將key-value通過XML、EJB、Ofbiz、JDBC、JDO等進行存儲,也可以自己實現AbstractPropertySet從而自定義更多的存儲形式。PropertySet最典型的適用存儲數據是配置信息、用戶首選項等。在項目中,如果一些可以轉化為key-value的信息在一開始無法確定存儲位置,或者想可以靈活改變存儲位置,那就可以考慮使用PropertySet。(來源:https://blog.csdn.net/inkfish)
PropertySet的優點是:1.輕量級;2.靈活;3.易用;4.適用於J2SE和J2EE平台。(來源:https://blog.csdn.net/inkfish)
PropertySet的配置 (來源:https://blog.csdn.net/inkfish)
Property默認提供的存取方式有:aggregate、cached、jdbc、ejb、javabeans、map、memory、serializable、serializable、ofbiz、hibernate、ojb、xml。(來源:https://blog.csdn.net/inkfish)
配置文件的放置位置為:(來源:https://blog.csdn.net/inkfish)
1.propertyset.xml
2./propertyset.xml
3.META-INF/propertyset.xml
4./META-INF/propertyset.xml
5.META-INF/propertyset-default.xml
6./META-INF/propertyset-default.xml
PropertySet會按以上順序挨個尋找,第一個被找到的即作為配置文件。由於propertyset的jar中自帶propertyset-default.xml,因此多數情況下無需配置即可使用(JDBC或Hibernate情況下,需要指定JNDI等信息,不可缺省)。(來源:https://blog.csdn.net/inkfish)
關於配置文件的書寫,可以參考默認配置文件,默認配置文件內容是:(來源:https://blog.csdn.net/inkfish)
<propertysets> <propertyset name="aggregate" /> <propertyset name="cached" /> <propertyset name="jdbc" > <arg name="datasource" value="jdbc/DefaultDS"/> <arg name="table.name" value="OS_PROPERTYENTRY"/> <arg name="col.globalKey" value="GLOBAL_KEY"/> <arg name="col.itemKey" value="ITEM_KEY"/> <arg name="col.itemType" value="ITEM_TYPE"/> <arg name="col.string" value="STRING_VALUE"/> <arg name="col.date" value="DATE_VALUE"/> <arg name="col.data" value="DATA_VALUE"/> <arg name="col.float" value="FLOAT_VALUE"/> <arg name="col.number" value="NUMBER_VALUE"/> </propertyset> <propertyset name="ejb" /> <propertyset name="javabeans" /> <propertyset name="map" /> <propertyset name="memory" /> <propertyset name="serializable" /> <propertyset name="ofbiz" /> <propertyset name="hibernate" > <arg name="hibernate.connection.datasource" value="jdbs/DefautDS" /> <arg name="hibernate.dialect" value="net.sf.hibernate.dialect.HSQLDialect" /> </propertyset> <propertyset name="ojb" /> <propertyset name="xml" /> </propertysets>
注:PropertySet項目中錯別字很多,比如“<arg name="hibernate.connection.datasource" value="jdbs/DefautDS" />
”中的“jdbs/DefautDs
”其實應該寫成“jdbc/DefaultDS
”。(來源:https://blog.csdn.net/inkfish)
(待續)(來源:https://blog.csdn.net/inkfish)
最後更新:2017-04-02 04:01:44