Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Created February 19, 2015 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhirockzz/e8cff17670b897b6d142 to your computer and use it in GitHub Desktop.
Save abhirockzz/e8cff17670b897b6d142 to your computer and use it in GitHub Desktop.
Valid CDI scopes for Stateless beans
//This is valid
@Stateless
@Dependent
public class EJB1 {
@PostConstruct
public void init(){
System.out.println(EJB1.class.getName() + " constructed successfully on "+ new Date().toString());
}
}
//This is NOT valid
@Stateless
@RequestScoped
public class EJB1 {
@PostConstruct
public void init(){
System.out.println(EJB1.class.getName() + " constructed successfully on "+ new Date().toString());
}
}
//CDI container will complain
Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-000082: Scope interface javax.enterprise.context.RequestScoped is not allowed on stateless enterprise beans for class cdi.ejb.integration.EJB1. Only @Dependent is allowed on stateless session beans.
at org.jboss.weld.bean.SessionBean.checkScopeAllowed(SessionBean.java:122)
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