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