Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g (10.1.3.5.0)

Part Number E13981-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

Looking Up an EJB 3.0 Resource Manager Connection Factory

Using EJB 3.0, you can look up a resource manage connection using resource injection (see "Using Annotations") or the InitialContext (see "Using Initial Context").

Using Annotations

Example 19-24 shows how to use annotations and dependency injection to access an EJB 3.0 resource manager connection factory.

Example 19-24 Injecting an EJB 3.0 Resource Manager Connection Factory

@Stateless public class EmployeeServiceBean implements EmployeeService {
    ...
    public void sendEmail(String emailAddress) {
        @Resource Session testMailSession;
        ...
    }
}

Using Initial Context

Example 19-25 shows how to use the initial context to look up an EJB 3.0 resource manager connection factory.

Example 19-25 Looking Up an EJB 3.0 Resource Manager Connection Factory

@Stateless public class EmployeeServiceBean implements EmployeeService {
    ...
    public void sendEmail(String emailAddress) {
        InitialContext ic = new InitialContext();
        Session session = (Session) ic.lookup("java:comp/env/mail/testMailSession");
        ...
    }
}

For more information, see "Configuring the Initial Context Factory".