Created
February 19, 2015 10:05
-
-
Save abhirockzz/e8cff17670b897b6d142 to your computer and use it in GitHub Desktop.
Valid CDI scopes for Stateless beans
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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