Reputation: 578
In my Java EE aplication I use the following snippet to obtain BeanManager
public static BeanManager getBeanManager() {
try {
InitialContext initialContext = new InitialContext();
return (BeanManager) initialContext.lookup("java:comp/BeanManager");
} catch (NamingException e) {
throw new RuntimeException("Failed to retrieve BeanManager!", e);
}
}
Would it be safe to use BeanManager as singleton, so I would not have to lookup in initial context each time I need BeenManager?
Upvotes: 2
Views: 235
Reputation: 1764
If you want to use the BeanManager into a standard EE(v6-v7) component then it is perfectly legal and recommended to simply do:
@Inject BeanManager beanManager
Upvotes: 2