@Target(value={PARAMETER,FIELD,METHOD,CONSTRUCTOR,ANNOTATION_TYPE}) @Retention(value=RUNTIME) @Documented @Qualifier public @interface ConfigProperty
A default implementation is provided in DeltaSpike for basic String injection points:
@Inject @ConfigProperty(name="locationId") private String locationId;
It's possible to use config properties in a type-safe manner, which requires a custom producer:
@Target({FIELD, METHOD}) @Retention(RUNTIME) @ConfigProperty(name = "locationId") @Qualifier public @interface Location { }
@Location private String locationId;
@ApplicationScoped public class CustomConfigPropertyProducer extends BaseConfigPropertyProducer { @Produces @Dependent @Location public String produceLocationId(InjectionPoint injectionPoint) { String configuredValue = getStringPropertyValue(injectionPoint); if (configuredValue == null) { return null; } return configuredValue; } }
Producers can be implemented to support other types of injection points:
@Inject @Location private LocationId locationId;
@ApplicationScoped public class CustomConfigPropertyProducer extends BaseConfigPropertyProducer { @Produces @Dependent @Location public LocationId produceLocationId(InjectionPoint injectionPoint) { String configuredValue = getStringPropertyValue(injectionPoint); if (configuredValue == null) { return null; } return LocationId.valueOf(configuredValue.trim().toUpperCase()); } }For custom producer implementations,
BaseConfigPropertyProducer
can
be used as the base class.ConfigResolver
,
BaseConfigPropertyProducer
Modifier and Type | Fields and Description |
---|---|
static String |
NULL
This constant is a workaround for the java restriction that Annotation values cannot be set to null.
|
Modifier and Type | Required Element and Description |
---|---|
String |
name
Name/key of the property.
|
Modifier and Type | Optional Element and Description |
---|---|
String |
defaultValue
Optional default value.
|
public static final String NULL
public abstract String name
public abstract String defaultValue
Copyright © 2015 The Apache Software Foundation. All rights reserved.