MySQL DataSource for Wildfly10 like Openshift

how to configure Wildfly10 to have a DataSource for MySQL like Openshift the RedHat Cloud.

I installed Wildfly10 on ~/srv/wildfly-10.0.0.Final

Step 1: Add MySQL Driver to modules:

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

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

copy  mysql-driver mysql-connector-java-5.1.38.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.38.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: add Driver and Datasource in standalone.xml

cd wildfly-10.0.0.Final//standalone/configuration/
edit standalone.xml
find <subsystem xmlns="urn:jboss:domain:datasources:2.0">
add MySQL datasource and driver:

<datasources>
  <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
  ...
  </datasource>
  <!-- add MySQL DataSource here: -->
  <datasource 
    jndi-name="java:jboss/datasources/MySQLDS" 
    pool-name="MySQLDS" 
    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>

 <driver name="h2" module="com.h2database.h2">
                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                    </driver>
<!-- add MySQL Driver here: -->
 <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 is encoded UTF-8-bin.



Kommentare

Beliebte Posts aus diesem Blog

Java EE 7 Petclinic

start glassfish4 javadb running jdk1.7.0_51

WildFly 8 Final is released!