Since @ManagedBean(eager = true)
will be deprecated, How do you create a eager application scoped cdi bean?
Solved this by making use of CDI extension framework:
Create Qualifier:
@Qualifier
@Target(value = {ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
@Retention(value = RetentionPolicy.RUNTIME)
public @interface Eager {
}
Create Extension implementation with observer method:
public class EagerCDIExtension implements Extension {
public void afterDeploymentValidation(@Observes AfterDeploymentValidation event, BeanManager beanManager) {
beanManager.getBeans(Object.class, new AnnotationLiteral<Eager>() {
}).parallelStream().filter(bean -> bean.getBeanClass().isAnnotationPresent(ApplicationScoped.class)).forEach(bean -> {
beanManager.getReference(bean, bean.getBeanClass(), beanManager.createCreationalContext(bean)).toString();
});
}
}
Create: META-INF/services/javax.enterprise.inject.spi.Extension
Register extension implementatoin class in above file i.e:
pypackage.EagerCDIExtension
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With