wildfly registering mysql as a datasource

前端 未结 5 849
隐瞒了意图╮
隐瞒了意图╮ 2021-01-14 14:17

I have been trying to configure mysql as a datasource in wildfly. I am not sure what i am missing out, i get an error on startup .

I have the mysql-connector-java-5

相关标签:
5条回答
  • 2021-01-14 14:50

    This may happen when you download the mysql connector zip and uploading the zip as a deployment. But the correct way is to unzip your download and point to the contained jar.

    0 讨论(0)
  • 2021-01-14 14:50

    There are three ways using which you can simply create datasource into wildfly

    1. Using admin console
    2. Manually adding into standalone.xml
    3. Creating datasource file that is xml file.

    Go to WildFly directory/standalone/deployments Simplest way to create datasource xml with following content

    <datasources xmlns="http://www.jboss.org/ironjacamar/schema">
          <datasource jndi-name="APP_DS" pool-name="APP_DS" enabled="true" use-ccm="false">
            <connection-url>jdbc:mysql://localhost:3306/DB_NAME</connection-url>
            <driver-class>com.mysql.jdbc.Driver</driver-class>
            <driver>mysql</driver>
    
            <!-- sql to call when connection is created -->
            <new-connection-sql>SELECT 1</new-connection-sql>
    
            <pool>
                <min-pool-size>5</min-pool-size>
                <max-pool-size>50</max-pool-size>
            </pool>
    
            <security>
              <user-name>username</user-name>
              <password>password</password>
            </security>
    
            <!-- sql to call on an existing pooled connection when it is obtained from pool -->
            <validation>
            <check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
            </validation>
    
            <timeout>
            <blocking-timeout-millis>300000</blocking-timeout-millis>
            <idle-timeout-minutes>5</idle-timeout-minutes>
            </timeout>
            <statement>
            <track-statements>true</track-statements>
            </statement>      
          </datasource>
        </datasources>
    
    0 讨论(0)
  • 2021-01-14 14:56

    I have working configuration of mysql driver on wildfly.

           <datasources>
                // ...
                <drivers>
                    // ...
                    <driver name="mysql" module="com.mysql.jdbc">
                        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                        <driver-class>com.mysql.jdbc.Driver</driver-class>
                        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                        <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                    </driver>
                </drivers>
            </datasources>
    

    The little difference seems to be presence of "driver-class" tag.

    I hope it will help.

    (Deploying mysql driver as a deployment also works and it's recommended way. https://docs.jboss.org/author/display/WFLY8/DataSource+configuration )

    [edit]

    I have mysql module under wildfly/modules/com/mysql/jdbc/main/ . I've noticed just now you module path doesn't correspond to module name. And I haven't find any doc's just yet, but I don't think you should mess with modules/system directory.

    module.xml

    <?xml version="1.0" ?>
    <module xmlns="urn:jboss:module:1.1" name="com.mysql.jdbc">    
        <resources>
            <resource-root path="mysql-connector-java-5.1.31-bin.jar"/>
        </resources>
    
        <dependencies>
            <module name="javax.api"/>
            <module name="javax.transaction.api"/>
        </dependencies>
    </module>
    
    0 讨论(0)
  • 2021-01-14 15:06

    To resolve the mysql datasource configuration issue on Wildfly i used the admin console to add the datasource and test it.

    1. If you login to the web console and find the datasource you tried configuring disable that a remove it . The standalone.xml and the module.xml get reset to the orginal.

      Steps for accessing web console

    2. Configure a new datasource :

      name :mysql
      JNDI :java:jboss/datasources/proj

    3. Click next and enter the url (i used the below) and click enable and then click test
      url : jdbc:mysql://localhost/proj

    4. The test should show success

    5. The changes to the standalone.xml and the module.xml are automatically made .

    6. If you restart the server now it should start without any errors and you should be able to access the database from your web project

    0 讨论(0)
  • 2021-01-14 15:06

    Two things: I just got mine working, and have the driver and xml located in $JBOSS_HOME/modules/com/mysql/jdbc/main - I'm fairly new with this as well so I'm not sure if that matters. Another thing: I don't know if it is just a typo, but if it was just copied and pasted it looks like your JAR name is incorrect

    <resource-root path="mysql-connector-java-5.0.8.jar"/>
    

    when it should be

    <resource-root path="mysql-connector-java-5.0.8-bin.jar"/>
    

    I forgot the .jar in mine, and that ended up fixing it. Hope that helps!

    0 讨论(0)
提交回复
热议问题