Last active
March 30, 2018 00:59
-
-
Save os890/a0974e7f03bba5e0266da86ec2769007 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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