Portal instance (Company) specific properties

Liferay provides lot customizations formats using preferences, configuration, properties etc. Developer knows and remembers general ways and possible settings, most commons we go with portal-ext.properties having required settings to apply on portal and place this in classpath. Specifying key-values in portal-ext.properties applies to whole server and available everywhere in portal. Cool. We can override existing properties or add new and use that in code.

We can create lot of sites and users, even we can create multiple portal instances. Each portal instance may focus on specific type of sites, specific functionality and end users. Lets suppose there are multiple portal instances (For Pet lovers, Books buyers, Fragrance manufacturers) we have created. Each instance wants to attract users so provides user registration. Well users can visit each portal instance site and register themself. User sets there reminder question and answer for in case of need. It would be very nice that we provide specific set of reminder questions to users. For example, Pet lovers site may provide questions related to pets, Books lovers site may give question specific to books etc.

But there is just one property we can set in portal-ext.propertie indicating set of questions. sad

Liferay have solution for this as well and we can have different set of properties files, specific to portal instance and out of box, nothing to install seperately. WOW.

So we can add portal instance (company) specific properties in its specific properties file and place them in classpath. Out of box liferay functionality or our custom functionality may work according to value for them..

Really cool. But how to achieve this? Its quiet easy... by following 2 steps:

 

1. Portal Instance specific properties file

Create portal instance specific properties file with specific pattern of file name (Don't worry, we do not need to specify all the properties, just key-values which will be different for specific portal instance)

Every portal instance (Company) have its company web id we specify during creation of portal instance. Suppose company web id is "BOOKSPORTAL" (liferay.com for default created portal instance) then we create a property file with pattern

portal-<WebId>.properties

Example:
portal-BOOKSPORTAL.properties
portal-PETPORTAL.properties
portal-FREGRANCEPORTAL.properties
portal-liferay.com.properties

Place these files files in server classpath. Better along with portal-ext.properties.

 

Specify server to handle property loading per portal instance 

By default Liferay do not check for instance based properties file. So to do so, we need to request liferay that it should load properties files considering instance wide properties files. For this we need to add following system property company-id-properties with value "true". This can be passed as VM argument so add

-Dcompany-id-properties=true

 

Now when you restart the server, and you will notice that portal instance specific properties are also loaded and available per portal. There is no need to alter the way you retrieve the property. Existing code to retrieve property value will return the company specific property value.

As already mentioned above, there is no need to specify all the properties in specific properties file, so portal-<WebId>.properties is loaded after portal-ext.properties that means you can have common value in portal-ext and if want to change it for portal instance, just add this key-value in instance specific file.

 

Blogs
Yogesh, great post to highlight this feature; one of many underrated fatures! Thank you very much for sharing this piece!
Hello Yogesh,

thank you for this blog-post! Actually, I'm working on a project right now where we have to make use of this feature a lot.
The problem is (correct me if I'm wrong): it is not that well documented!
We tried to configure the property "velocity.engine.restricted.classes" in a company-specific way. As of now: this is not possible because the Velocity-Enginge is created at startup using the property. This might be a corner-case because of the Velocity-Enginge.
BUT: IMHO all the properties defined in com.liferay.portal.util.PropsValues can not be defined company-specific because they are resolved at class-loading-time!

For all other/custom properties this feature really works like charme.

Kind regards from Germany
Henry
This didn't work for me. I can see at startup that the file is being loaded but the values that I specify are not being overridden. I did read somewhere that not all the properties are overrideable but I have yet to find any information outlining which of them are and which of them are not.
This article probably could be helpful:

https://www.liferay.com/group/customer/knowledge/kb/-/knowledge_base/article/30717691