Using a Service Locator
See Also
A service locator is a class that provides a single, reusable way to obtain
a reference to the following:
- An enterprise bean's local and/or remote home interfaces
- A JMS connection factory and topic destination
- An e-mail session
- A JDBC data source
- The URL, name, or boolean value for an environment entry
You can create a regular service locator or one that caches the obtained reference
for further use. Generally you use a caching service regulator in web applications
and a regular service locator in the business tier. Enterprise beans especially
need non-caching service locators. Because each enterprise bean has a unique
JNDI name space, a resource reference with the same name can be declared in
multiple enterprise beans, potentially with different types.
To create a service locator:
- Choose File > New.
- From the Enterprise category, select Service Locator or Caching Service
Locator.
To use a service locator:
- Run any of the following commands:
- Call Enterprise Bean
- Use Database
- Send JMS Message
- Send E-Mail
- In the Service Locator Strategy section, select Use Existing Class and specify
the class name of the service locator. You can use the Browse button to search
for the class.
Notes:
- The service locator template is fully functional. You do not need to modify
the code, although you can customize its caching behavior.
- You can only create a service locator in a web application project or EJB
module project.
- See Also
- Calling an Enterprise Bean
- Sending a JMS Message
- Accessing a Connection Pool from a Java Class
- Sending an E-mail from a Java File
Legal Notices