Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Created February 19, 2015 10:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save abhirockzz/3ba7da2643849e246f09 to your computer and use it in GitHub Desktop.
Valid CDI scopes for Singleton EJBs
//This is legal
@Singleton
@Startup
@ApplicationScoped
public class Singleton1 {
@PostConstruct
public void init(){
System.out.println(Singleton1.class.getName() + " constructed successfully on "+ new Date().toString());
}
}
//CDI container will not be happy seeing this
@Singleton
@Startup
@RequestScoped
public class Singleton1 {
@PostConstruct
public void init(){
System.out.println(Singleton1.class.getName() + " constructed successfully on "+ new Date().toString());
}
}
Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-000083: Scope interface javax.enterprise.context.RequestScoped is not allowed on singleton enterprise beans for class cdi.ejb.integration.Singleton1. Only @Dependent and @ApplicationScoped is allowed on singleton session beans.
at org.jboss.weld.bean.SessionBean.checkScopeAllowed(SessionBean.java:125)
at org.jboss.weld.bean.SessionBean.internalInitialize(SessionBean.java:101)
at org.jboss.weld.bean.RIBean.initialize(RIBean.java:66)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$5.doWork(ConcurrentBeanDeployer.java:118)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$5.doWork(ConcurrentBeanDeployer.java:115)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:59)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:52)
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_25]
... 3 more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment