Java 无法将 mysql 驱动程序添加到 jboss

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19319171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 16:03:46  来源:igfitidea点击:

Can't add mysql driver to jboss

javamysqljboss7.x

提问by Oscht?rEi

Ok this is driving me crazy. Especially because there are already many similar questions out there. But no answer works for me.

好吧,这让我发疯。特别是因为已经有很多类似的问题。但没有答案对我有用。

I have jboss 7.1.1 on my windows 7 machine (running it from eclipse normally) and want to use mysql.

我的 Windows 7 机器上有 jboss 7.1.1(正常从 eclipse 运行它)并且想使用 mysql。

I did the following:

我做了以下事情:

1 created directory jboss-as-7.1.1.Final\modules\com\mysql\main

1 创建目录 jboss-as-7.1.1.Final\modules\com\mysql\main

2 Files there: module.xmland mysql-connector-java-5.1.26-bin.jar(downloaded from official mysql site)

2 个文件:module.xmlmysql-connector-java-5.1.26-bin.jar(从官方 mysql 站点下载)

3 Content of module.xml:

3 内容module.xml

<?xml version="1.0" encoding="UTF-8"?>
<modulexmlns="urn:jboss:module:1.0" name="com.mysql">
  <resourxces>
     <resource-rootpath="mysql-connector-java-5.1.26-bin.jar"/>              
  </resources>
  <dependencies>
     <modulename="javax.api"/>
  </dependencies>
</module>

4 Relevant parts from jboss-as-7.1.1.Final\standalone\configuration\standalone.xml:

4 相关部分来自jboss-as-7.1.1.Final\standalone\configuration\standalone.xml

<datasource jndi-name="java:jboss/datasources/mysqlDS" pool-name="mysqlDS" enabled="true" jta="true"  use-ccm="true" use-java-context="true">
    <connection-url>jdbc:mysql://192.168.1.1:3306/eAuftrag</connection-url>
    <driver>com.mysql</driver>
    <security>
        <user-name>root</user-name>
        <password>fffff</password>
    </security>
    <timeout>  
        <idle-timeout-minutes>0</idle-timeout-minutes>  
        <query-timeout>600</query-timeout>  
    </timeout>  
    <statement>  
        <prepared-statement-cache-size>100</prepared-statement-cache-size>  
        <share-prepared-statements>true</share-prepared-statements>  
    </statement>  
</datasource>

and:

和:

 <driver name="com.mysql" module="com.mysql" />


Everytime I start the jboss server I see this message:

每次启动 jboss 服务器时,我都会看到以下消息:

service jboss.jdbc-driver.com_mysql (missing) dependents: [service jboss.data-source.java:jboss/datasources/mysqlDS]

service jboss.jdbc-driver.com_mysql (missing) dependents: [service jboss.data-source.java:jboss/datasources/mysqlDS]

And when I go to the managment-console and look at datasources, the mysqlDS is listed there, but when I click on it I get the error (sorry can't select the text there, so here comes the image):

当我转到管理控制台并查看数据源时,mysqlDS 列在那里,但是当我单击它时,我收到错误消息(抱歉,无法在那里选择文本,因此图像来了):

error from managment console

来自管理控制台的错误

采纳答案by Oscht?rEi

So once more I can pay tribute to my stupidity. I did everything right except I had typos in my module.xmlfile. Notice that in the code above are no blanks (" ") between some words - somehow they got lost. But what's even worse is that apparantly these module-files are not validated by jboss, that's why I never realized it. Anyway here's the correct config without the typos...

所以我可以再次向我的愚蠢表示敬意。除了我的module.xml文件中有错别字外,我做的一切都是正确的。请注意,在上面的代码中,某些单词之间没有空格 (" ") - 它们不知何故丢失了。但更糟糕的是,这些模块文件显然没有经过 jboss 验证,这就是为什么我从未意识到这一点。无论如何,这是没有错别字的正确配置......

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

回答by Sai prateek

To make the JDBC driver classes available to the JBoss Application Server, copy the archive mysql-mysql-connector-java-5.1.5-bin.jar from the Connector/J distribution to the lib directory in the default server configuration (assuming that is the server configuration you're running).

要使 JDBC 驱动程序类可用于 JBoss 应用程序服务器,请将存档 mysql-mysql-connector-java-5.1.5-bin.jar 从 Connector/J 发行版复制到默认服务器配置中的 lib 目录(假设是您正在运行的服务器配置)。

Now create a mysql-ds.xml

现在创建一个 mysql-ds.xml

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
  <jndi-name>DefaultDS</jndi-name>
  <connection-url>jdbc:mysql://localhost:3306/test</connection-url>
  <driver-class>com.mysql.jdbc.Driver</driver-class>
  <user-name>root</user-name>
  <password>jboss</password>
  <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
  <metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>

you can also refer this links https://zorq.net/b/2011/07/12/adding-a-mysql-datasource-to-jboss-as-7

你也可以参考这个链接 https://zorq.net/b/2011/07/12/adding-a-mysql-datasource-to-jboss-as-7

http://docs.jboss.org/jbossas/getting_started/v4/html/db.html

http://docs.jboss.org/jbossas/getting_started/v4/html/db.html

回答by James R. Perkins

You need to give the driver tag a driver class or a data source.

您需要为驱动程序标记提供驱动程序类或数据源。

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

回答by Samy

Here is my sample module.xml

这是我的示例 module.xml

<module xmlns="urn:jboss:module:1.1" name="com.mysql">

<resources>
    <resource-root path="mysql-connector-java-5.1.6.jar"/>
    <!-- Insert resources here -->
</resources>
<dependencies>
          <module name="javax.api"/>
          <module name="javax.transaction.api"/>
</dependencies>

Below is the Data source configuration in standalone.xml

下面是standalone.xml中的数据源配置

<datasource jta="true" jndi-name="java:jboss/jdbc/MyDS" pool-name="AppzillonDS"         enabled="true" use-java-context="true">
  <connection-url>jdbc:mysql://192.168.1.98:3306/mydb?zeroDateTimeBehavior=convertToNull</connection-url>
  <driver>mysql</driver>
    <security>
       <user-name>user</user-name>
       <password>password</password>
    </security>
</datasource>

Look at the driver tag in above. drive is just mysqland not the com.mysql. Hope this should help you....

查看上面的驱动程序标签。驱动器只是mysql而不是com.mysql. 希望这对你有帮助......

回答by Nguyen

Make sure you do NOT have a space at the beginning of module.xmlfile or you will get a:

确保module.xml文件开头没有空格,否则您将得到:

new missing/unsatisfied dependencies

...error for this driver.

...此驱动程序的错误。

回答by JAGJ jdfoxito

WILDFLY 10 using mysql 5.7

WILDFLY 10 使用 mysql 5.7

follow this steps: comment or delete exampleds in standalone.xml

请按照以下步骤操作:在 standalone.xml 中注释或删除示例

  1. into jboss-cli.bat --connect
  1. 进入 jboss-cli.bat --connect

after execute command [standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=mysql:add(driver-name=mysql,driver-module-name=com.mysql,driver-xa-datasource-class-name=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource)

执行命令后 [standalone@localhost:9990 /] /subsystem=datasources/jdbc-driver=mysql:add(driver-name=mysql,driver-module-name=com.mysql,driver-xa-datasource-class-name= com.mysql.jdbc.jdbc2.optional.MysqlXADataSource)

should be ok

应该可以

this modified standalone.xml, then add

这个修改了standalone.xml,然后添加

<datasources>
<!--
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
    <user-name>sa</user-name>
    <password>sa</password>
</security>
</datasource> -->
<datasource jndi-name="java:/mysql" pool-name="mysqlDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/wildfly</connection-url>
<driver>mysql</driver>
<security>
    <user-name>root</user-name>
    <password>jdfoxito10</password>
</security>
</datasource>
<drivers>
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>

should look like!

应该看起来像!

and module.xml put in

和module.xml放入

\java\server\wildfly-10.1.0.Final\modules\system\layers\base\com\mysql\main

\java\server\wildfly-10.1.0.Final\modules\system\layers\base\com\mysql\main

mysql-connector-java-5.1.40-bin.jar (come installer mysql-installer-community-5.7.15.0.msi) module.xml

mysql-connector-java-5.1.40-bin.jar(来安装程序mysql-installer-community-5.7.15.0.msi)module.xml

and content from module.xml like:

和 module.xml 中的内容,如:

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

and ready, JAVA_HOME should be ok

准备好了,JAVA_HOME 应该没问题