Skip to main content Skip to complementary content

OSGI Configuration Parameters for Spring Components

About this task

If you are using a Java client and using OSGi configuration parameters, then follow these steps.

To use jasypt with spring components:


  1. Add the following Maven dependencies:
  2. Add the usual properties, but the encrypted property should be wrapped by the ENC() function.
    <osgix:cm-properties id="properties" persistent-id="my">
      <prop key="mydb.password">ENC(fAdXf/ed2k+2uD1LhoOpvw==)</prop>
  3. Add the password and the algorithm configuration for encryptor.
    <bean id="environmentVariablesConfiguration" class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
       <property name="algorithm" value="PBEWITHSHA256AND128BITAES-CBC-BC"/>
       <property name="password" value="TESB_ENV_PASSWORD"/>
  4. Create the encryptor and inject configuration to it.
    <bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
       <property name="config" ref="environmentVariablesConfiguration"/>
  5. Add the property configurer and pass the properties to it. The EncryptablePropertyPlaceholderConfigurer will read the .properties files and make their values accessible as ${var}.
    <bean id="propertyConfigurer"
       <constructor-arg ref="configurationEncryptor"/>
       <property name="properties" ref="properties"/>
  6. Now, you can use the properties as usual:
    <bean id="serviceBean" class="">
        <property name="prop" value="${mydb.password}"/>

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!