Search code examples
sap-commerce-cloud

Environment Variables in Hybris local.properties


I'm wondering if, in a Hybris properties file, there is a way to reference environment variables.

For example, in local.properties: my.property = ${MY_ENVIRONMENT_VARIABLE}

My searching has concluded that this is possible in Spring, but doesn't appear to work in Hybris.

Any thoughts would be appreciated.


Solution

  • No it's not possible.

    Actually hybris use org.apache.commons.configuration package. In the documentation you'll find that it's possible to use environment variable.

    user.file = ${sys:user.home}/settings.xml
    action.key = ${const:java.awt.event.KeyEvent.VK_CANCEL}
    java.home = ${env:JAVA_HOME}
    

    Unfortunately hybris has done something I can't explain, they have overidded the default implementation and removed all interpolation features.

    If we analyze the issue further, the configuration class used is called HybrisConfiguration. This class extends AbstractConfiguration from Apache Commons Configuration. The getProperty method use an other interface called ConfigIntf. The implementation is found in the class AbstractConfig. There every getString getInteger, etc... methods are overrided.

    For example, for String, the method does not call the interpolate method but instead you'll find a really simple...

    StringUtils.isEmpty(value) ? def : value;
    

    So if you want to use all features of Apache API, then try to replace hybris implementation... However I think that it won't be so easy to do that without modifying the platform since I don't see any beans there that could be injected.