meanwhile, I did this, I hope is not wrong The Websocket inherit this abstract class, and that work public abstract class CdiBootstrap {
private final static Logger logger = LoggerFactory.getLogger(CdiBootstrap.class);
private static BeanManager beanManager = null;
public BeanManager getBeanManager() { if (null == beanManager) { try { InitialContext initialContext = new InitialContext(); beanManager = (BeanManager) initialContext.lookup("java:comp/env/BeanManager"); } catch (NamingException e) { } } return beanManager; }
public <T> T getBean(Class<T> cls) { BeanManager bm = getBeanManager(); logger.info("Generate bean from {}, cause native injection doesn't work."); Set<Bean<?>> beans = bm.getBeans(cls, DEFAULT_AT); Bean<?> b = beans.iterator().next(); final CreationalContext context = bm.createCreationalContext(b); return cls.cast(bm.getReference(b, b.getBeanClass(), context)); }
private static final Annotation DEFAULT_AT = new AnnotationLiteral<Default>() { private static final long serialVersionUID = 1L; }; }
|