tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From afryer <>
Subject Using @Inject to inject one EJB into another sometimes causes exceptions when EJBContainer is closed
Date Thu, 15 Mar 2012 10:20:46 GMT
Recently when shutting down TomEE (4.0.0-beta2) I have been getting the
following exception...

SEVERE: Exception thrown while destroying bean instance : [Stateless2,
Name:null, WebBeans Type:ENTERPRISE, API
java.lang.IllegalStateException: Bean 'Stateless2' has been undeployed.

The problem seems to be related to the use of the @Inject annotation and
doesn't happen if @EJB is used instead.  

I have created a test case to duplicate the error.  The classes are below...

public interface Stateless1Service {
	public String toUpper(String input);

public class Stateless1 implements Stateless1Service {
 	// exception doesn't occur if @EJB is used here instead.
	@Inject Stateless2Service stateless2;
	public String toUpper(String input) {
		return input.toUpperCase();

public interface Stateless2Service {
	public String toLower(String input);

public class Stateless2 implements Stateless2Service {
	public String toLower(String input) {
		return input.toLowerCase();

public class OpenEjbContainerTest {
	private EJBContainer ejbContainer;
	@Inject Stateless1Service stateless1;
	public void setUp() throws NamingException {
		Properties p = new Properties();
		p.put("openejb.deployments.classpath.include", ".*openejb.*");
		ejbContainer = EJBContainer.createEJBContainer(p);
        ejbContainer.getContext().bind("inject", this);
	public void cleanUp() {
		if (ejbContainer != null) {
                        // Exception is thrown here
	public void testToUpper() {
		System.out.println("Testing toupper()...");
		System.out.println("ToUpper of hello is " + stateless1.toUpper("hello"));

View this message in context:
Sent from the OpenEJB User mailing list archive at

View raw message