Introduction

smartics-properties-integration-cdi is an extension of smartics-properties to support cdi injection. Right now only weld is supported.

If you want to define properties, please refer to smartics-properties-config .

Having the properties declared and defined you can - using this extension - inject them using cdi.

Quickstart

Configuration

When you are using maven, add the following dependencies to your pom.xml:
        <dependency>
          <groupId>de.smartics.properties</groupId>
          <artifactId>smartics-properties-integration-cdi</artifactId>
          <version>${project.version}</version>
        </dependency>
Having added the dependency it is also necessary to specify the groupId, artifactId and version that shall be used to lookup the properties. The default is using the data from your pom by copying them to the manifest.mf file of your archive or by providing them manually by using the following keys:
Implementation-Vendor-Id: ${project.groupId}
          Implementation-Title: ${project.artifactId}
          Implementation-Version: ${project.version}
The following maven-plugins can help you putting this information in the manifest.mf : An example for the maven-ear-plugin:
<plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-ear-plugin</artifactId>
          <version>2.3.2</version>
          <configuration>
            ...
            ...
            <archive>
              <manifest>
                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
              </manifest>
            </archive>
          </configuration>
        </plugin>
An example for the maven-ear-plugin manually configuring the values:
<plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-ear-plugin</artifactId>
          <version>2.3.2</version>
          <configuration>
            ...
            ...
            <archive>
              <manifestEntries>
                <Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id>
                <Implementation-Title>${project.artifactId}</Implementation-Title>
                <Implementation-Version>${project.version}</Implementation-Version>
              </manifestEntries>
            </archive>
          </configuration>
        </plugin>
Last but not least the node and environment must be set. This can be done by using the following java system properties in JAVA_OPTS:
  • properties.environment.node
  • properties.environment.name

e.g. (windows): set "JAVA_OPTS=%JAVA_OPTS% -Dproperties.environment.node=node1 -Dproperties.environment.name=production"

e.g. (linux): JAVA_OPTS="$JAVA_OPTS -Dproperties.environment.node=node2 -Dproperties.environment.name=preproduction"

Usage / Injection

Now comes the simple part: Injecting the properties / using one.
package de.smartics.sandbox;
import javax.ejb.Stateless;
import javax.inject.Inject;

import de.smartics.sandbox.ApplicationProperties;

@Stateless
public class SimplePropertiesService
{
  @Inject
  private ApplicationProperties appProperties;

  /**
   * Do something.
   */
  public void doSomething()
  {
    final String url = appProperties.url();
    ...
  }
}
ApplicationProperties is the Interface defining the property keys as documented in smartics-properties