Create or changing a resource reference
A resource reference supports application access to a resource (such as a data source, URL, or mail provider) using a logical name rather than the actual name in the runtime environment. This capability eliminates the necessity to alter application code when you change the resource runtime configurations.
This topic guides you through updating the resource references of an enterprise application that you assembled previously. The topic, Assembling applications, details the assembly procedure.
Resource references are declared in the deployment descriptor by the application provider. At some point in the application deployment process, you must bind the resource reference to the actual name of the resource in the run time environment. When creating a connection factory or data source in the application server, the application server provides a JNDI name that a component can use to access that connection factory or data source. The application server uses an indirect name with the java:comp/env prefix. For example:
- When creating a data source, the default JNDI name is set to jdbc/data_source_name.
- When creating a connection factory, its default name is eis/j2c_connection_factory_name.
If we override these values by specifying our own, retain the java:comp/env prefix. An indirect JNDI name allows the connection management infrastructure to access to any data from the resource reference that is associated with the application. This allows us to better manage resources based on the settings for authentication, isolation level, sharing scope, and resolution control.
This topic describes how to update the resource references of an enterprise application using an assembly tool. After you define the resource reference, we can perform an indirect JNDI lookup using the java:comp/env context.
- Start an assembly tool.
- If we have not done so already, configure the assembly tool for work on Java EE modules.
- Import the enterprise application (EAR file) to change into the EJB project.
- Display the resource references for the type of module:
- If an enterprise bean uses the resource reference:
- Expand the name of the EAR file.
- Expand EJB Modules.
- Expand the EJB module wanted.
- Expand the section for the appropriate type of enterprise bean (Session Beans or Entity Beans).
- Expand the enterprise bean.
- If a servlet uses the resource reference:
- Expand the name of the EAR file.
- Expand Web Modules.
- Expand the web module wanted.
- If an application client uses the resource reference:
- Expand the name of the EAR file.
- Expand Application Clients.
- Expand the application client module wanted.
- Right-click the module whose resource references to change and click Open With > Deployment Descriptor Editor.
- For servlets and application clients, click Add. For EJB modules, select the particular bean and click Add.
- Select the resource reference option and click Next.
- Specify the settings for the resource reference, and click Finish.
- Optional: Select the References tab and, under WebSphere Extensions, select an isolation level. If we choose to forego this step, the isolation level defaults to TRANSACTION_NONE.
- Optional: Under WebSphere Bindings, specify a JNDI name. If we choose to forego this step we can set (or override) the binding when the application is deployed.
- Close the deployment descriptor editor and save the changes.
Results
Files for the updated module are shown in the Project Explorer view.
What to do next
Verify the contents of the updated enterprise application in the Project Explorer view. Then, deploy the enterprise application.We can generate EJB deployment code and deploy an EJB module to a target server in one step. In the Project Explorer view, right-click on the EJB project and click Deploy. See also the topic, Deploying EJB modules.
Related concepts
Data sources Data source lookups for enterprise beans and web modules Development and assembly tools
Related tasks
Install enterprise application files Assembling applications Deploy EJB modules
Develop applications that use JNDI Direct and indirect JNDI lookup methods for data sources Connection factory JNDI name practices Resource references **** MISSING FILE ****