Configure Java EE default resources
Use the administrative console or wsadmin commands to configure bindings for Java EE default resources.
New feature:
The Java EE specification defines six default resources, which WAS v9 provides in its default configuration. We configure a Java EE default resource provider by binding the JNDI name for a default resource to the JNDI name of a configured resource. For example, we can bind java:comp/DefaultDataSource to a data sourcedata source in the product.newfeat
Java EE default resources
Each default resource has a class name and a JNDI name. Bind a resource to the corresponding WebSphere resource type.
Resource class Java EE JNDI name WebSphere resource type javax.sql.DataSource java:comp/DefaultDataSource JDBC Data Source javax.enterprise.concurrent.ContextService java:comp/DefaultContextService Work Manager javax.enterprise.concurrent.ManagedExecutorService java:comp/DefaultManagedExecutorService Work Manager javax.enterprise.concurrent.ManagedScheduledExecutorService java:comp/DefaultManagedScheduledExecutorService Work Manager javax.enterprise.concurrent.ManagedThreadFactory java:comp/DefaultManagedThreadFactory Work Manager javax.jms.ConnectionFactory java:comp/DefaultJMSConnectionFactory JMS Connection Factory
Tasks
- In the administrative console, click...
Resources > Java EE default resources to go to the Java EE default resource settings page.
- Specify a scope.
The scope indicates the location for the resource configuration file. Each Java EE default resource has a binding configurable at each of the cell, node, and server scopes. By default, bindings are set for each default resource at the cell scope only. We can configure default resource bindings at all, some, or none of the configurable scopes.
If multiple bindings exist for a default resource, the product resolves the bindings with the following priority:
- 1. Server scope
- 2. Node scope
- 3. Cell scope
For example, if a default data source is bound to jdbc/myCellDataSource at the cell scope and jdbc/myServerDataSource at the server scope for the server1 server, any lookup of...
java:comp/DefaultDataSource
...on server1 resolves to...
jdbc/myServerDataSource
If another server server2 exists in the cell with no binding at the node or server scope, a lookup of...
java:comp/DefaultDataSource
...resolves to...
jdbc/myCellDataSource
- Bind a Java EE default resource to a configured resource.
For example, to bind the default data source to a configured JDBC data source, select a data source from the list for Default Datasource. By default, each java:comp/Defaultxxx binding references a corresponding built-in resource provided by the product.
Consider the following information when configuring the resource provider:
- Default data source
- The default data source in the default configuration is a Derby Embedded data source, which is not supported in a production environment.
To use a supported default data source in a production environment, we must reconfigure the bindings for the default data source to reference a data source supported.
- Concurrent default resources
- Unlike the default data source and default JMS connection factory, the default concurrency resources do not have a one-to-one correspondence with resources types in the WebSphere configuration. Instead, the WorkManager resource implements all four of the concurrency resources. By default, all four EE Concurrency default resources are bound to a single built-in WorkManager resource with the wm/default JNDI name. We can bind these default resources to different WorkManager resources.
- JMS default resources
- The default JMS connection factory is available only at the cell scope, and references the SIBus named defaultBus. To use the default JMS connection factory, either create the Service Integration Bus named defaultBus or modify the default JMS connection factory Bus name property in the administrative console to reference the intended SIBus. In either case, we must add the members (application servers) to the bus, and choose the type of messageStore (FileStore or DataStore) for the persistence, to get the messaging engine run time.
- Click OK.
After completing these steps, applications can find the Java EE default resource by doing a lookup that uses its corresponding java:comp/Defaultxxx JNDI name.
Example
The following code examples show how an application can find a default resource.
- Lookup that uses @Resource injection
@Resource(lookup = "java:comp/DefaultDataSource") DataSource defaultDatasource;- JNDI lookup
DataSource defaultDs = (DataSource) new InitialContext().lookup("java:comp/DefaultDataSource");- @Resource annotation without the lookup, which defaults to the corresponding JNDI name defined by the Java EE specification
@Resource DataSource defaultDatasource;
What to do next
We can configure the properties of a resource to which a Java EE default resource is bound. For example, suppose java:comp/DefaultDataSource is bound to jdbc/myDatasource and to set the maximum pool size of java:comp/DefaultDataSource to 10. To do this, set the maximum pool size of jdbc/myDataSource to 10. For information on how to modify properties of various resources, see the related links.
Related:
Data sources JMS connection factories and service integration Work managers Configure a JDBC provider and data source Configure a unified connection factory for the default messaging provider Configure work managers Java EE default resource settings JavaEEDefaultResources Administrative console scope settings