Java Reference
In-Depth Information
Table 5.8. Methods of EJBContainer
Method
Description
close()
Shuts down the in-memory EJB container.
createEJBContainer()
Creates an EJBContainer using default properties.
Creates an EJBContainer providing values for some proper-
ties.
createEJBContainer(Map<?,?>)
getContext()
Returns javax.naming.Context.
Registering EJBs
When using the default createEJBContainer() bootstrap method, the application's
class path will be scanned for EJBs. If you don't want the entire class path scanned, or
if for some reason you want only specific EJBs loaded, use createEJBContainer
(java.util.Map<?,?>) and configure the map with names of the modules you want
loaded. For example, this configuration will scan for EJBs only in the bidservice.jar and
accountservice.jar files; there may be other EJBs in other modules but they'll be ignored.
Properties props = new Properties();
props.setProperty(
EJBContainer.MODULES, new String[]{"bidservice","accountsevice"});
EJBContainer ec = EJBContainer.createEJBContainer(props);
When an EJB is found, the embedded container will bind the EJB to JNDI using the port-
able global JNDI name, the same as a full EE server. For example, suppose on the class
path there's bidservice.jar, which has an @Local com.bazaar.BidServiceLocal
interface with an @Stateless com.bazaar.BidServiceEjb implementation. The
embedded container will bind the following:
java:global/bidservice/BidServiceEjb
java:global/bidservice/BidServiceEjb!com.bazaar.BidServiceLocal
EJBs with @Local interfaces or no-interface EJBs are allowed in the embedded container.
@Remote beans aren't supported by the embedded container.
Performing EJB lookups
EJB lookups are the same as any other JNDI lookup. For classes not managed by the em-
bedded container, use the Context provided by EJBContainer.getContext() to
perform the lookup. For example, get the BidServiceLocal EJB as follows:
 
Search WWH ::




Custom Search