tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From afryer <apfr...@hotmail.com>
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
Types:[openejb.ejbs.Stateless2Service,java.lang.Object],
Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]]
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...

@Local
public interface Stateless1Service {
	public String toUpper(String input);
}

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

@Local
public interface Stateless2Service {
	public String toLower(String input);
}

@Stateless
public class Stateless2 implements Stateless2Service {
	@Override
	public String toLower(String input) {
		return input.toLowerCase();
	}
}

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



--
View this message in context: http://openejb.979440.n4.nabble.com/Using-Inject-to-inject-one-EJB-into-another-sometimes-causes-exceptions-when-EJBContainer-is-closed-tp4474463p4474463.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Mime
View raw message