You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by afryer <ap...@hotmail.com> on 2012/03/15 11:20:46 UTC
Using @Inject to inject one EJB into another sometimes causes
exceptions when EJBContainer is closed
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.
Re: Using @Inject to inject one EJB into another sometimes causes
exceptions when EJBContainer is closed
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,
i fixed several issues regarding such thing on trunk, can you give it a
try? (4.0.0-beta-3-SNAPHOT)
- Romain
2012/3/15 afryer <ap...@hotmail.com>
> 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.
>