Skip to content

Instantly share code, notes, and snippets.

@karlkilden
Created April 22, 2015 08:39
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 karlkilden/e69282b67c370de92711 to your computer and use it in GitHub Desktop.
Save karlkilden/e69282b67c370de92711 to your computer and use it in GitHub Desktop.
public class EndUsage {
@Inject
private MyBean myBean;
// Use the dynamic bean
}
@Alternative // This is not the one we want injected
public class MyBean {
// Add implementation here
}
public class MyBeanProducer {
private MyBean bean;
@Produces
public MyBean myBeanProducer() {
return bean;
}
@PostConstruct
private void determineBean() {
bean = new MyBean(); // This could be any logic you want. MyBean could be the interface and here you could choose the implemtation
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment