Customize properties in Liferay

本文介绍了一种方法,通过将Twitter API URL等动态配置项放入properties文件中,实现无需重新编译项目即可轻松更新配置值。演示了如何在Liferay Portlet项目中创建并使用properties文件,并提供了获取文件中属性值的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Sometimes, we need to put our property in properties file, because those properties might be changed in the near future. For example, in my twitter portlet, the twitter api I use to fetch tweets might be changed. A good design is to put the api url in properties. Later we don't need to change code and recompile the whole project. We only need to change the property value in properties file.

In Liferay, there are several ways to do that. Now I'd like to show the simplest way to do that.

1. create a properties file name portlet.properties in /WEB-INF/src folder

2. edit your portlet.properties like:

twitter.api=https://api.twitter.com/1/statuses/user_timeline.json?screen_name=

3. get the value of "twitter.api" in your controller or other classes

String value = com.liferay.util.portlet.PortletProps.get("twitter.api");

It's really easy, right?


I also found other ways to do that, but I haven't tried them. 

http://www.liferay.com/community/wiki/-/wiki/Main/How+to+add+a+Properties+File+to+a+Portlet

http://www.liferay.com/community/wiki/-/wiki/Main/Adding+Custom+Properties

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值