Search code examples
javaopen-libertymicroprofile

Substitution and injection from bootstrap.properties doesn' t work


In my pom I define some profile-dependent properties

<profiles>
        <profile>
            <!-- localhost -->
            <id>LOCAL</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <ADServiceUID>uid-c0a84980-33489f60-15ca1a4bd66--7ff7</ADServiceUID>
                <LDAPServiceUID>uid-c0a84980-4e8eaad4-15d55058ca2--7efe</LDAPServiceUID> 
                <WLAN_VPNServiceUID>uid-c0a84980-4e8eaad4-15d55058ca2--7ef6</WLAN_VPNServiceUID>
                <MailboxServiceUID>uid-c0a84980-33489f60-15ca1a4bd66--7f1b</MailboxServiceUID>
                <BiolAuthServiceUID>uid-7f001-5698ac8b-15e9a06bf32--7fbf</BiolAuthServiceUID>
                <HestAuthServiceUID>uid-c0a84980--166b2589-1646afda4f8--7ff0</HestAuthServiceUID>
                <ItetAuthServiceUID>uid-7f001-5698ac8b-15e9a06bf32--7fbd</ItetAuthServiceUID>
                <LdapsProxyServiceUID>uid-c0a84980--562f2389-15f29329a10--7126</LdapsProxyServiceUID>
                <OpenDirServiceUID>uid-c0a8f781--4baed631-15ec752b318--7d1a</OpenDirServiceUID>
                <PhysicMailServiceUID>uid-c0a84980-33489f60-15ca1a4bd66--7fed</PhysicMailServiceUID>
                <ADUserPrivGrpServiceUID>uid-ac10be8b-172512a1-15f483b1c37--7fc9</ADUserPrivGrpServiceUID>
            </properties>
        </profile>
    </profiles>

Then in my bootstrap.properties I define the same props which should be set depending on the profile I specify when building my application

## UIDs of the IT-Services (set in pom)
it-service.ad = ${ADServiceUID}
it-service.ldap = ${LDAPServiceUID}
it-service.wlan_vpn = ${WLAN_VPNServiceUID}
it-service.mailbox = ${MailboxServiceUID}
it-service.biolauth = ${BiolAuthServiceUID}
it-service.hestauth = ${HestAuthServiceUID}
it-service.itetauth = ${ItetAuthServiceUID}
it-service.ldaps_proxy = ${LdapsProxyServiceUID}
it-service.opendirectory = ${OpenDirServiceUID}
it-service.physik_mail = ${PhysicMailServiceUID}
it-service.ad_userprivategroup = ${ADUserPrivGrpServiceUID}

I run mvn clean install and the bootstrap.properties under target/classes has the values set

## UIDs of the IT-Services (set in pom)
it-service.ad = uid-c0a84980-33489f60-15ca1a4bd66--7ff7
it-service.ldap = uid-c0a84980-4e8eaad4-15d55058ca2--7efe
it-service.wlan_vpn = uid-c0a84980-4e8eaad4-15d55058ca2--7ef6
it-service.mailbox = uid-c0a84980-33489f60-15ca1a4bd66--7f1b
it-service.biolauth = uid-7f001-5698ac8b-15e9a06bf32--7fbf
it-service.hestauth = uid-c0a84980--166b2589-1646afda4f8--7ff0
it-service.itetauth = uid-7f001-5698ac8b-15e9a06bf32--7fbd
it-service.ldaps_proxy = uid-c0a84980--562f2389-15f29329a10--7126
it-service.opendirectory = uid-c0a8f781--4baed631-15ec752b318--7d1a
it-service.physik_mail = uid-c0a84980-33489f60-15ca1a4bd66--7fed
it-service.ad_userprivategroup = uid-ac10be8b-172512a1-15f483b1c37--7fc9

while the the same file under src/main/liberty/config still has the placeholders.

Moreover, when I try to read these properties in my application, they are null

@Inject
  @ConfigProperty( name = "it-service.ad" )
  private Provider<String> itServiceADUID;

  @Inject
  @ConfigProperty( name = "it-service.ldap" )
  private Provider<String> itServiceLdapUID;

  @Inject
  @ConfigProperty( name = "it-service.wlan_vpn" )
  private Provider<String> itServiceWlanVpnUID;

  @Inject
  @ConfigProperty( name = "it-service.mailbox" )
  private Provider<String> itServiceMailboxUID;
...

private void initITServiceUIDs()
  {
    this.itServiceUIDs = new HashMap<>();
    this.itServiceUIDs.put("AD", this.itServiceADUID.get());  <--- line 230
    this.itServiceUIDs.put("Ldap", this.itServiceLdapUID.get());
    this.itServiceUIDs.put("Mailbox", this.itServiceMailboxUID.get());
    this.itServiceUIDs.put("Wlan_Vpn", this.itServiceWlanVpnUID.get());
...
  }

The error message:

Caused by: java.lang.NullPointerException
[INFO]  at ch.ethz.id.sws.iamws.dirxwsclient.service.ServiceClient.initITServiceUIDs(ServiceClient.java:230)

What am I missing or doing wrong?


Solution

  • Francesco, first check that the class you are injecting config into is properly enabled as a CDI bean (with a bean definiting annotation or with a valid beans.xml present).

    Second, where are you calling initITServiceUIDs from? If you call it from a constructor then the fields will not yet have been injected.