|
consider the following startup extension that replicate the ejb @Singleton @Startup behavior :
public class StartupExtension implements Extension
{
private final Set<Bean<?>> startupBeans = new LinkedHashSet<Bean<?>>();
<X> void processBean(@Observes ProcessBean<X> event)
{
if (event.getAnnotated().isAnnotationPresent(Startup.class) &&
event.getAnnotated().isAnnotationPresent(ApplicationScoped.class))
{
startupBeans.add(event.getBean());
}
}
void afterDeploymentValidation(@Observes AfterDeploymentValidation event, BeanManager manager)
{
for (Bean<?> bean : startupBeans)
{
// the call to toString() is a cheat to force the bean to be initialized
manager.getReference(bean, bean.getBeanClass(), manager.createCreationalContext(bean)).toString();
}
}
}
in weld 2.0.0.Beta6 it will lead in an new IllegalStateException(METHOD_NOT_AVAILABLE_DURING_INITIALIZATION, methodName) exception (BeanManagerProxy::checkContainerInitialized)
though as https://issues.jboss.org/browse/CDI-315 suggests, it should not.
|