2012年11月21日 星期三

JBoss 5.0 DefaultDS Configuration using MySql

說明 JBoss AS 5.0 配置 MySQL DataSource。


準備執行環境

預設JBoss AS 5.0 及 MySQL Server 5.1 已配置這裡不再贅述
  • JDK (Java Development Kit) version 1.6
  • JBoss Enterprise Application Platform 5.0
  • MySQL Server 5.1



JBoss Server Configuration

  1. 下載JDBC driver for MySQLDownload Connector/J,下載後.jar放置路徑如下:%JBOSS_HOME%\server\PROFILE\lib\mysql-connector-java-x.x.xx-bin.jar。 (here PROFILE means all,produciton,default etc)

  2. 新增%JBOSS_HOME%\server\PROFILE\deploy\mysql-ds.xml內容如下,移除%JBOSS_HOME%\server\PROFILE\deploy\hsqldb-ds.xml(這裡的移除都沒有實際移除而是rename)。
  3. <?xml version="1.0" encoding="UTF-8"?>
    <datasources>
       <local-tx-datasource>
          <jndi-name>DefaultDS</jndi-name>
          <use-java-context>true</use-java-context>
          <connection-url>jdbc:mysql://localhost:3306/test</connection-url>
          <driver-class>com.mysql.jdbc.Driver</driver-class>
          <user-name>test</user-name>
          <password>test</password>
          <metadata>
             <type-mapping>mySQL</type-mapping>
          </metadata>
       </local-tx-datasource>
    </datasources>
    


  4. mysql-ds.xml - type-mapping屬性,需配合%JBOSS_HOME%\server\PROFILE\conf\standardjbosscmp-jdbc.xml設定,大小寫需完全符合。
  5.       <type-mapping>
             <name>mySQL</name>
             <row-locking-template>SELECT ?1 FROM ?2 WHERE ?3 ORDER BY ?4 FOR UPDATE</row-locking-template>
             <pk-constraint-template>CONSTRAINT ?1 PRIMARY KEY (?2)</pk-constraint-template>
             ....
          </type-mapping>
    


    另外從JBoss web-console可看到所有的TypeMappingNamesmysql-ds.xml - type-mapping屬性需配合這邊的設定:


  6. 如有使用JBoss JMS 則需做以下修改,不過如設定的PROFILEdefault,即使沒有使用 JMS 還是需做以下設定否則會有 Error - Cannot create timer table ,複製 %JBOSS_HOME%\docs\examples\jms\mysql-persistence-service.xml%JBOSS_HOME%\server\PROFILE\deploy\messaging\,接著移除%JBOSS_HOME%\server\PROFILE\deploy\messaging\hsqldb-persistence-service.xml(rename)。


  7. Start MySQL,接著Start JBoss,JBoss 正常啟動也可看到建立如下 Table,則配置成功。


相關設定可參考:
How to switch Hypersonic with an alternative database in JBoss ?
Cannot create timer table

2 則留言:

  1. Thaitanium Art Studio - Titha Technology
    Thaitanium Art Studio is a t fal titanium pan creative and titanium hip collaborative art studio ion titanium on brassy hair for artists who create titanium iv chloride high-quality art. View Thaitanium art's latest projects and exhibitions titanium razor

    回覆刪除