Project configuration in Hybris

Written by: Mario Grunitz

icon representing two gears

There are a lot of instances when a number or string should be able to be adjusted in environments outside of your development machine. In these cases, environment variables are a good choice. However, the Hybris platform provides a more convenient approach. Let’s see how.

Global and local properties

The first place of the configuration is in the platform’s project.properties:

Project.properties of the whole platform

This file contains the global properties for the whole Hybris platform. By using it you can configure:

  • tomcat
  • DB access
  • web security settings
  • Hybris cluster
  • Hybris Management Console
  • Hybris Administration Console
  • cockpits
  • cron jobs
  • mail senders
  • logging
  • etc.

A lot of setting entries have some default values. But this file isn’t a good place to make custom changes. For this, the local.properties file inside the config folder exists:

Local properties

The entries inside this file override the same ones from the project.properties of the platform. So, you need to place everything you need to configure for the platform inside this file.

Extension configuration

Besides global configuration, each Hybris extension has its own configuration file. See below the project.properties file with some configuration items.

Training’s extension properties file

How to change properties

You’re able to view all available properties and change them inside Hybris Administration Console. For this, go here and you will see the following page:

Hybris Administration Console configuration section

You can use the search box to find properties you want to change. Please be aware that all changes will be lost after the server reload due to the fact that all changes are stored only in memory (information in the yellow block on the screenshot).

How to read properties

I’ve figured out several ways to read the properties during the Hybris development process. Let’s go through each of them:

Firstly, you can read them in the source code. Hybris offers de.hybris.platform.util.Config which has a pretty straightforward API. For example:

Config.getParameter(“<keyPath>”)
Config.getString(“<keyPath>”)
Config.getChar(“<keyPath>”)
Config.getBoolean(“<keyPath>”)
Config.getInt(“<keyPath>”)
Config.getLong(“<keyPath>”)
Config.getDouble(“<keyPath>”)

If such a key path exists then an appropriate value will be returned. If not, then the method will return a null value.

The second way you can read properties is inside impex files. Impex framework is used inside the Hybris platform to perform import data procedures. You can use defined properties inside an impex file to make your import procedure more flexible and abstract. For example:

# Import modulegen config properties into impex macros

Update

GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.ConfigPropertyImportProcessor];pk[unique=true]
$jarResourceCms=$config-jarResourceCmsValue
$emailPackageName=$config-emailContextPackageName

The code above imports two properties into an impex script: jarResourceCmsValue and emailContextPackageName. Those items, of course, exist in the config section of the HAC.

Conclusions

The Hybris platform provides developers a convenient and flexible approach for configuring applications. The one very interesting feature for me is that you can use properties not only inside Java code, but in the impex scripts as well, which helps us to create very dynamic data imports.

Happy hacking!

(Visited 215 times, 1 visits today)
Last modified: April 17, 2020
Author info
Mario Grunitz
Mario is a WeAreBrain Co-founder. With more than 15 years of experience in the tech space, he has worked all over Europe and held countless leadership positions in corporate, startup and agency spheres.
Close