Configuring Java EE default resources

You can use the administrative console or wsadmin commands to configure bindings for Java™ Platform Enterprise Edition (Java EE) default resources.

About this task

New feature New feature:
The Java EE specification defines six default resources, which the product provides in its default configuration. You configure a Java EE default resource provider by binding the Java Naming and Directory Interface (JNDI) name for a default resource to the JNDI name of a configured resource. For example, you can bind java:comp/DefaultDataSource to a data source that is configured in the product.newfeat
Table 1. Java EE default resources. Each default resource has a class name and a JNDI name. You must 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

Procedure

  1. In the administrative console, click Resources > Java EE default resources to go to the Java EE default resource settings page.
  2. 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. You 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.
  3. Bind a Java EE default resource to a configured resource.

    For example, to bind the default data source to a configured Java Database Connectivity (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.
    Avoid trouble Avoid trouble: To use a supported default data source in a production environment, you must reconfigure the bindings for the default data source to reference a data source that is supported.gotcha
    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. You 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, you 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.
  4. Click OK.

    After you complete these steps, applications can find the Java EE default resource by doing a lookup that uses its corresponding java:comp/Defaultxxx JNDI name. The Example section shows code that your application can use to find a resource.

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

You 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 you want 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.


Icon that indicates the type of topic Task topic



Timestamp icon Last updated: March 5, 2017 17:27
File name: tdat_jeedefaultres.html