JBoss EAP 6.x 上要建立 MySQL 的 Java Naming and Directory Interface (JNDI) 作法分三個步驟如下:

Step 01: 在 $JBOSS_HOME 目錄 modules 下建立 mysql 相關資訊

$ mkdir -p $JBOSS_HOME/modules/com/mysql/main/
$ touch $JBOSS_HOME/modules/com/mysql/main/module.xml

 

Step 02: 維護 $JBOSS_HOME/modules/com/mysql/main/module.xml 內容如下

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.mysql">
  <resources>
    <resource-root path="mysql-connector-java-5.1.7-bin.jar"/>
  </resources>
  <dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
  </dependencies>
</module>

MySQL 的 JDBC Jar 檔可以從 http://dev.mysql.com/downloads/connector/j/ 網站下載,並將下載的檔案 mysql-connector-java-x.x.x-bin.jar 放在 $JBOSS_HOME/modules/com/mysql/main 裡。

Step 03: 這裡以 JBoss EAP standalone Mode 作為範例,修改 $JBOSS_HOME/standalone/configuration/standalone.xml

<profile>
...
<subsystem xmlns="urn:jboss:domain:datasources:1.1">
    <datasources>
        ...               
        <datasource jndi-name="java:jboss/datasources/ExampleInfinispanDS" pool-name="ExampleInfinispanDS" enabled="true" use-java-context="true" use-ccm="true">
            <connection-url>jdbc:mysql://localhost:3306/EXAMPLEINFINISPAN</connection-url>
            <driver>mysql</driver>
            <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
            <pool>
                <min-pool-size>10</min-pool-size>
                <max-pool-size>100</max-pool-size>
                <prefill>true</prefill>
            </pool>
            <security>
                <user-name>root</user-name>
                <password>root</password>
            </security>
            <validation>
                <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
                <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
            </validation>
            <timeout>
                <!-- using default timeout values -->
            </timeout>
            <statement>
                <prepared-statement-cache-size>100</prepared-statement-cache-size>
                <share-prepared-statements>true</share-prepared-statements>
            </statement>
        </datasource>
        <drivers>
            ...
            <driver name="mysql" module="com.mysql">
                <datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlDataSource</datasource-class>
            </driver>
        </drivers>
    </datasources>
</subsystem>
</profile>

 

再重啟 JBoss EAP standalone Mode: $JBOSS_HOME/bin/standalone.bat 即可

 

 

參考:

http://magnus-k-karlsson.blogspot.tw/2013/08/complete-configuration-of-mysql-5.html

http://www.vogella.com/tutorials/MySQLJava/article.html

https://access.redhat.com/documentation/en-US/JBoss_Enterprise_BRMS_Platform/5/html/BRMS_Administrator_Guide/Configuring_a_Datasource_for_JBoss_Enterprise_Application_Platform_6.html

JBoss EAP 6.1 Administration and Configuration Guide. Chapter 6.6. Datasource Configuration

MySQL 5 Manual. Chapter 22.3.5.1 Driver/Datasource Class Names, URL Syntax and Configuration Properties for Connector/J

文章標籤
創作者介紹
MIS

MISTECH 技術手抄本

MIS 發表在 痞客邦 PIXNET 留言(0) 人氣()