MySQL as Default Database in WildFly 8.0.0.CR1

How to  replac the H2 Database for Default DataSource in JBoss WildFly 8.0.0.CR1:

Step 1: Add MySQL Driver to modules:

Download the mysql-driver mysql-connector-java-5.1.22.jar from any Maven Repository e.g.: http://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.22/

go to WildFly modules Directory:
cd wildfly-8.0.0.CR1/modules/system/layers/base
mkdir -p mysql/mysql-connector-java/main

copy  mysql-driver mysql-connector-java-5.1.22.jar here.

add a file module.xml with content:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" 
        name="mysql.mysql-connector-java">
    <resources>
        <resource-root path="mysql-connector-java-5.1.22.jar"/>
        <!-- Insert resources here -->
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.servlet.api" optional="true"/>
    </dependencies>
</module>


Step 2: replace Driver and Datasource in standalone.xml

cd wildfly-8.0.0.CR1/standalone/configuration/
edit standalone.xml
find <subsystem xmlns="urn:jboss:domain:datasources:2.0">
comment out datasource and driver.
add:

<datasources>
  <datasource 
    jndi-name="java:jboss/datasources/ExampleDS" 
    pool-name="ExampleDS" 
    enabled="true" 
    use-java-context="true">
    <connection-url>jdbc:mysql://localhost:3306/wildfly?useUnicode=yes&amp;characterEncoding=UTF-8</connection-url>
    <driver>com.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>wildfly</user-name>
       <password>wildflypwd</password>
    </security>
    <statement>
      <prepared-statement-cache-size>32</prepared-statement-cache-size>
      <share-prepared-statements>true</share-prepared-statements>
    </statement>
 </datasource>
 <drivers>
    <driver name="com.mysql" module="mysql.mysql-connector-java">
      <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
     </driver>
 </drivers></datasources>


change credentials for your needs. insure the database beeing enconded UTF-8-bin.


Kommentare

Beliebte Posts aus diesem Blog

Java EE 7 Petclinic

Simulated Evolution - Artificial Life and DNA

Diffusion-limited aggregation