To configure a JDBC data source for a web application in JBOSS, perform the following steps:
- Add a reference to the data source in web.xml:
<resource-ref>
<description>My Data Source</description>
<res-ref-name>jdbc/my-data-source</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref> - Map the reference name to a JBOSS-style JNDI name in the
vendor-specific data source, jboss-web.xml:
<resource-ref>
<res-ref-name>jdbc/my-data-source</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:/my-data-source</jndi-name>
</resource-ref> - Create a data source for the JBOSS-style JNDI name by
creating a data source file named my-data-source-ds.xml
in the JBOSS deploy directory, containing:
<datasources>
<local-tx-datasource>
<jndi-name>my-data-source</jndi-name>
<connection-url>jdbc:some url</connection-url>
<driver-class>some.driver</driver-class>
<user-name>user</user-name>
<password>password</password>
<max-pool-size>20</max-pool-size>
<min-pool-size>0</min-pool-size>
<blocking-timeout-millis>5000</blocking-timeout-millis>
<prepared-statement-cache-size>0</prepared-statement-cache-size>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
</local-tx-datasource>
</datasources>