Skip to content

Instantly share code, notes, and snippets.

@os890
Last active March 30, 2018 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save os890/a0974e7f03bba5e0266da86ec2769007 to your computer and use it in GitHub Desktop.
Save os890/a0974e7f03bba5e0266da86ec2769007 to your computer and use it in GitHub Desktop.
public class MultiProfileExtension implements Extension {
private Set<String> activeProfileNames = new HashSet<>();
protected void determineActiveProfiles(@Observes BeforeBeanDiscovery beforeBeanDiscovery) {
String activeProfileString =
ConfigResolver.getPropertyValue("active-profiles", "Production");
Collections.addAll(activeProfileNames, activeProfileString.split(","));
}
protected void matchActiveProfiles(@Observes ProcessAnnotatedType pat, BeanManager bm) {
Set<Annotation> annotations = pat.getAnnotatedType().getAnnotations();
Profile profile = AnnotationUtils.findAnnotation(
bm, annotations.toArray(new Annotation[annotations.size()]), Profile.class);
if (profile == null) {
return;
}
for (String supportedProfile : profile.value()) {
if (activeProfileNames.contains(supportedProfile)) {
return;
}
}
pat.veto();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment