Skip to content

Instantly share code, notes, and snippets.

@Qkyrie
Created July 17, 2013 07:42
Show Gist options
  • Save Qkyrie/6018530 to your computer and use it in GitHub Desktop.
Save Qkyrie/6018530 to your computer and use it in GitHub Desktop.
ConfigValue Producer for automatically injecting configuration strings
@Produces
@ConfigValue("")
@Dependent
public String configValueProducer(InjectionPoint ip) {
// We know this annotation WILL be present as WELD won't call us otherwise, so no null checking is required.
ConfigValue configValue = ip.getAnnotated().getAnnotation(ConfigValue.class);
// This could potentially return a null, so the function is annotated @Dependent to avoid a WELD error.
return props.getProperty(configValue.value());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment