Connection Pool データソースの設定

前提

  • OS: Oracle Linux Server release 7.6
  • apache-tomcat: 9.0.34
  • java version: 1.8.0_241
    • Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
    • Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)

手順

1. webapps/<コンテキスト名>/META-INF/context.xml に DataSource Resource の設定を登録する

<!--?xml version="1.0" encoding="UTF-8"?-->
<Context>
 <Resource
  name="jdbc/oracledb"
  auth="Container"
  type="oracle.jdbc.pool.OracleDataSource"
  factory="oracle.jdbc.pool.OracleDataSourceFactory"
  maxTotal="100"
  maxIdle="30"
  maxWaitMillis="10000"
  username="GRAPHUSER"
  password="WELCOME1"
  alternateUsernameAllowed="true"
  driverClassName="oracle.jdbc.driver.OracleDriver"
  url="jdbc:oracle:thin:graphuser/WELCOME1@oracle-db:1521/pdb1"
  defaultAutoCommit="false" />
</Context>

2. webapps/<コンテキスト名>/WEB-INF/web.xml に Connection Pool 用のリソースを参照できるように設定する

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         id="WebApp_ID" version="3.1" metadata-complete="true">
    ....
    <resource-ref>
      <description>Connection Pool</description>
      <res-ref-name>jdbc/oracledb</res-ref-name>
      <res-type>oracle.jdbc.pool.OracleDataSource</res-type>
      <res-auth>Container</res-auth>
    </resource-ref>

3. java:comp/env/jdbc/oracledb のようにデータソースを lookup する