Description of problem: Using Singleton bean PreDestroy callback is a common way to perform tasks when server goes down. But calling Stateless bean methods in the callback code fails with the following error: javax.ejb.EJBException: JBAS014559: Invocation cannot proceed as component is shutting down Version-Release number of selected component (if applicable): EAP 6.1 How reproducible: Always Steps to Reproduce: 1. Start EAP 6.1 and deploy an application with a Singleton bean calling a Stateless bean method in its PreDestroy callback 2. Stop EAP 6.1 Actual results: Server shows an error "javax.ejb.EJBException: JBAS014559: Invocation cannot proceed as component is shutting down" and stops Expected results: Server calls Stateless bean method and stops. Additional info: Full stack trace http://pastebin.test.redhat.com/139645 The error message shown was introduced in this pull request: https://github.com/wildfly/wildfly/pull/1889
Created attachment 741906 [details] Sample application Added sample application showing the problem
As explained in an internal mail thread, you'll have to add a @DependsOn annotation on the singleton bean to depend on the stateless bean: @Singleton @Startup @javax.ejb.DependsOn("StatelessBean") // depend on the stateless bean public class SingletonBean { .... @PreDestroy public void shutdown() { System.out.println("###############################"); System.out.println("SingletonBean.shutdown"); System.out.println("###############################"); statelessBean.doSomething(); } }