How to configure datasource settings in JBoss EAP 6.x / 7.x
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.x
- 7.x
Issue
- How do I configure datasource setting in EAP 6.x / EAP7.x?
- Can I use a
*-ds.xml(as in EAP 4/5) in EAP 6.x / EAP 7.x? - How do I configure an XA datasource in EAP 6.x / EAP7.x?
- How do I deploy JDBC drivers in EAP 6.x / EAP7.x?
Resolution
In JBoss EAP 6.x/7.x, a JDBC driver may be installed as a simple JAR deployment or using a core module and configuration must be added to the standalone(-*).xml or domain.xml.
While using the old *-ds.xml configuration is still possible, it should only be used for development purposes and it is not recommended for production environments because it is not supported by the JBoss administrative and management tools. Please also refer to JBoss EAP 6 Migration Guide - 3.1.6. Datasource and Resource Adapter Configuration Changes.
There are three options for creating/configuring datasources in Red Hat JBoss Enterprise Application Platform (EAP)
1. Create datasource using the JBoss CLI
This is the recommended option because it includes auto-completion and eliminates typos.
See How to create a datasource using the JBoss CLI for more details.
2. Manual Configuration
The following is an example for Oracle, but the syntax is similar for other databases as well. Datasource example configurations for other databases may be found in the Configuration Guide for JBoss EAP 7 and JBoss EAP 6.
Install a JDBC driver as a core module
-
Create a directory under
$JBOSS_HOME/modules. In this example:"$JBOSS_HOME/modules/com/oracle/jdbc/main". -
Put the the JDBC driver jar (e.g.
ojdbc8.jar) in this directory. -
Create a module configuration file
module.xml:<module xmlns="urn:jboss:module:1.1" name="com.oracle.jdbc"> <resources> <resource-root path="ojdbc<VERSION_HERE>.jar"/> <!-- Supply the version number of the ojdbc driver --> </resources> <dependencies> <module name="javax.api"/> <module name="javax.transaction.api"/> </dependencies> </module>
Note that the jdbc driver jar must contain a META-INF/services/java.sql.Driver text file that specifies the jdbc driver class (JDBC4 compliant drivers should satisfy this requirement) or a driver-class will need to be explicitly specified.
NOTE : For domain configurations it is necessary to connect to and explicitly perform the above for each host that uses any profile where the driver will be registered and used to create datasources.
Register the driver and configure a datasource setting in standalone.xml or domain.xml.
You can now edit your standalone(-*).xml or domain.xml to configure a datasource that references this module:
<subsystem xmlns="urn:jboss:domain:datasources:1.2">
<datasources>
<datasource jndi-name="java:jboss/datasources/OracleDS" pool-name="OracleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:oracle:thin:@myhostname:1521:oracle</connection-url>
<driver>oracle</driver>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>20</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>myuser</user-name>
<password>mypass</password>
</security>
<validation>
<validate-on-match>true</validate-on-match>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"></valid-connection-checker>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter"></exception-sorter>
</validation>
</datasource>
<drivers>
<driver name="oracle" module="com.oracle.jdbc">
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
or for an xa-datasource:
<subsystem xmlns="urn:jboss:domain:datasources:1.2">
<datasources>
<xa-datasource jndi-name="java:/XAOracleDS" pool-name="XAOracleDS">
<driver>oracle</driver>
<xa-datasource-property name="URL">jdbc:oracle:thin:@myhostname:1521:oracle</xa-datasource-property>
<security>
<user-name>admin</user-name>
<password>admin</password>
</security>
<xa-pool>
<is-same-rm-override>false</is-same-rm-override>
<no-tx-separate-pools />
</xa-pool>
<validation>
<validate-on-match>true</validate-on-match>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"></valid-connection-checker>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter"></exception-sorter>
</validation>
</xa-datasource>
<drivers>
<driver name="oracle" module="com.oracle">
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
3. via the Console
The console ( http://<host>:9990/console/ ) can also be used to create datasources (module creation and driver registration using one of the above methods need to be completed first as these steps cannot be explicitly managed via the web console). Enter the information as prompted. Specific attributes (such as statistics) can be set prior to enabling the datasource.
Configuration -> <Profile> -> Connector -> Datasources
- See the Configuration Guide for JBoss EAP 7 and JBoss EAP 6 for additional pool, connection and statement configuration properties and their usage.
NOTE I: If there are missing/unsatisfied dependencies while using a non JDBC 4 compliant JDBC driver, see Getting New missing/unsatisfied dependencies when using non JDBC 4 compliant JDBC driver. Use of non-JDBC 4-compliant drivers is not recommended.
NORE II: Has a datasource been affected and does the boss have caching behavior for the datasource connection? does this mean that one must restart the server after changing the password? Yes, because the changes are not yet at runtime. Also, the connection pool reservation had already been made with the old password.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.