首页 文章

可以't use mysql driver with Wildfly 9.0.2 however It seems like it'正确加载

提问于
浏览
1

我正试图从glassfish切换到wildfly,但我很难 Build 与mysql db的连接 . 我已将.jar和module.xml放在/wildfly-9.0.2.Final/modules/system/layers/base/com/mysql/driver/main下 .

module.xml的内容:

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

在standalone.xml中我添加了一个条目:

<driver name="mysql" module="com.mysql.driver">
   <driver-class>com.mysql.jdbc.Driver</driver-class>
</driver>

这是有趣的部分,当我运行./standalnole.sh时,根本没有错误 . 它说mysql驱动程序盯着,但在数据源下的管理接口 - 检测到的驱动程序我没有看到它,只是原来的h2驱动程序 .

[0m13:22:59,551 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0018: Started Driver service with driver-name = mysql

你知道这个问题的解决方案吗?

2 回答

  • 0

    我使用命令行界面安装了postgresql-driver和module . 它结束于 .../wildfly-9.0.2.Final/modules/org/postgresql/main/ . 这是一个与你使用的不同的地方,但我不知道这是不是问题 .

    你的xml看起来不错,但驱动程序jar和module.xml文件可能不在正确的位置 . 尝试使用cli来安装它 . 以下是我安装驱动程序并为其创建数据源的方法:

    module add --name=org.postgresql --resources=/Users/jonmartinsolaas/Downloads/postgresql-9.4.1207.jar --dependencies=javax.api,javax.transaction.api
    

    添加模块时,jar文件被复制到wildfly中 . 如果您需要多个jar,请使用:as list separator .

    data-source add \
     --name=myDS \
     --driver-name=postgresql \
     --jndi-name=java:jboss/datasources/myDS \
     --connection-url="jdbc:postgresql://localhost/my-db" \
     --user-name=username \
     --password=secret \
     --use-ccm=false \
     --max-pool-size=25 \
     --blocking-timeout-wait-millis=5000 \
     --new-connection-sql="set datestyle = ISO, European;" \
     --check-valid-connection-sql="select 1" \
     --enabled=true
    

    如果您需要XA数据源:

    batch
       xa-data-source add \
        --name=mydsXA \
        --driver-name=postgresql \
        --jndi-name=java:jboss/datasources/mydsXA \
        --user-name=username \
        --password=secret \
        --recovery-username= username \
        --recovery-password = secret \
        --check-valid-connection-sql="select 1" \
        --use-ccm=false \
        --max-pool-size=25 \
        --blocking-timeout-wait-millis=5000 \
        --new-connection-sql="set datestyle = ISO, European;" \
        --enabled=true
    
        /subsystem=datasources/xa-data-source=paddaXA/xa-datasource-properties=ServerName:add(value=localhost)
        /subsystem=datasources/xa-data-source=paddaXA/xa-datasource-properties=PortNumber:add(value=5432)
        /subsystem=datasources/xa-data-source=paddaXA/xa-datasource-properties=DatabaseName:add(value=my-db)
    run-batch
    

    请注意,XA定义作为批处理(排序事务)运行,因此您必须"commit"使用 run-batch .

  • 0

    我看到了几个问题 . 首先,您没有部署它 . 最简单的方法是将 mysql-connector-java-<version>.jar 放入 <wildfly dir>/standalone/deployments .

    其次,您没有在standalone.xml中配置数据源 . 就像是:

    <subsystem xmlns="urn:jboss:domain:datasources:2.0">
        <datasources>
            <datasource jta="true" jndi-name="java:/MySQLDataSource" pool-name="MySQLDataSource" enabled="true" use-java-context="true" spy="false" use-ccm="true">
                <connection-url>jdbc:mysql://localhost:3306/mydatabase</connection-url>
                <driver-class>com.mysql.jdbc.Driver</driver-class>
                <driver>mysql-connector-java-<my version>.jar</driver>
                <pool>
                    <allow-multiple-users>false</allow-multiple-users>
                </pool>
                <security>
                    <user-name>xxx</user-name>
                    <password>xxx</password>
                </security>
                <validation>
                    <validate-on-match>false</validate-on-match>
                    <background-validation>false</background-validation>
                    <use-fast-fail>false</use-fast-fail>
                </validation>
                <timeout>
                    <set-tx-query-timeout>false</set-tx-query-timeout>
                    <blocking-timeout-millis>0</blocking-timeout-millis>
                    <idle-timeout-minutes>0</idle-timeout-minutes>
                    <query-timeout>0</query-timeout>
                    <use-try-lock>0</use-try-lock>
                    <allocation-retry-wait-millis>0</allocation-retry-wait-millis>
                </timeout>
                <statement>
                    <track-statements>NOWARN</track-statements>
                    <share-prepared-statements>false</share-prepared-statements>
                </statement>
            </datasource>
        </datasources>
    </subsystem>
    

相关问题