java Wildfly 9 无法在启动时加载 MySQL 驱动程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31250294/
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-11-02 18:20:32  来源:igfitidea点击:

Wildfly 9 failing to load MySQL driver on startup

javamysqljbosswildfly

提问by MTaylorEx

I am creating a web application for WildFly, which will connect to a MySQL database through JPA (Hibernate). For now, I am just trying to get WildFly to start up and load the MySQL driver in standalone mode. I am using this page as a guide: http://wildfly.org/news/2014/02/06/GlassFish-to-WildFly-migration/

我正在为 WildFly 创建一个 Web 应用程序,它将通过 JPA(休眠)连接到 MySQL 数据库。现在,我只是想让 WildFly 启动并以独立模式加载 MySQL 驱动程序。我使用此页面作为指南:http: //wildfly.org/news/2014/02/06/GlassFish-to-WildFly-migration/

I am running WildFly and MySQL locally on a Windows system:

我在 Windows 系统上本地运行 WildFly 和 MySQL:

  • Windows 7 Enterprise SP1
  • Oracle Java SE 1.8.0_45
  • WildFly 9.0.0.Final
  • MySQL Server 5.6
  • Windows 7 企业版 SP1
  • 甲骨文 Java SE 1.8.0_45
  • WildFly 9.0.0.Final
  • MySQL 服务器 5.6

Attempts to use the recommended console commands did not succeed, so I have manually edited to WildFly configuration files to look like those in the examples on the page linked above. First, I created the module directory and placed in it the MySQL connector JAR and module.xml file:

尝试使用推荐的控制台命令没有成功,所以我手动编辑了 WildFly 配置文件,使其看起来像上面链接页面上的示例中的那些。首先,我创建了模块目录并将 MySQL 连接器 JAR 和 module.xml 文件放入其中:

    Directory of C:\wildfly-9.0.0.Final\modules\system\layers\base\com\mysql\main

07/06/2015  09:54 AM    <DIR>          .
07/06/2015  09:54 AM    <DIR>          ..
07/06/2015  10:12 AM               334 module.xml
07/01/2015  02:38 PM           968,668 mysql-connector-java-5.1.35.jar

The above connector jar was copied from my local Maven repository, which Maven obtained through the following dependency:

上面的连接器 jar 是从我的本地 Maven 存储库中复制的,Maven 通过以下依赖项获得:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.35</version>
</dependency>

The module.xml file was manually edited as follows, to resemble the example I found on wildfly.org:

module.xml 文件被手动编辑如下,类似于我在 wildfly.org 上找到的示例:

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

Finally, I added the driver and datasource to the datasources section of standalone.xml:

最后,我将驱动程序和数据源添加到了 standalone.xml 的数据源部分:

        <datasource jndi-name="java:/MySQLDS" pool-name="MyDS" enabled="true" use-java-context="true">
            <connection-url>jdbc:mysql://localhost:3306/mydb</connection-url>
            <driver>mysql</driver>
            <security>
                <user-name>root</user-name>
                <password>secret</password>
            </security>
        </datasource>
        <drivers>
            <driver name="h2" module="com.h2database.h2">
                <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
            </driver>
            <driver name="mysql" module="com.mysql">
                <driver-class>com.mysql.jdbc.Driver</driver-class>
            </driver>
        </drivers>

Upon starting WildFly in standalone mode, by running %WILDFLY_HOME%\bin\standalone.bat, the following is the first error listed in %WILDFLY_HOME%\standalone\logs\server.log:

在独立模式下启动 WildFly 后,通过运行 %WILDFLY_HOME%\bin\standalone.bat,以下是 %WILDFLY_HOME%\standalone\logs\server.log 中列出的第一个错误:

2015-07-06 10:25:47,321 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 33) WFLYCTL0013: Operation ("add") failed - address: ([
    ("subsystem" => "datasources"),
    ("jdbc-driver" => "mysql")
]) - failure description: "WFLYJCA0041: Failed to load module for driver [com.mysql]"

Similar issues that I have seen posted on Stack Overflow and other question/answer sites usually point to an oversight such as a typo in config files or a misnamed file. However, I've been over this over and over and cannot see any such mistake, and the same error has occurred even after upgrading from Java SE 7 and WildFly 8.2 and re-creating the configuration files from scratch. Any assistance would be greatly appreciated.

我在 Stack Overflow 和其他问答网站上看到的类似问题通常指向疏忽,例如配置文件中的拼写错误或文件命名错误。然而,我一遍又一遍地重复这个,并没有看到任何这样的错误,即使从 Java SE 7 和 WildFly 8.2 升级并从头开始重新创建配置文件,同样的错误也发生了。任何帮助将不胜感激。

回答by Gianluca Elmo

In my case it was a matter of having the wrong user:group for the directories and files under ../com/mysql/main

在我的情况下,这是一个错误的问题:../com/mysql/main 下的目录和文件的组

I changed it to wildlfy and everything worked as expected.

我把它改成了wildlfy,一切都按预期进行。

回答by 6006604

In my case, it was an issue with double quotes. When I copied a WordPress sample of module.xml, I got (note the curly quotes):

就我而言,这是双引号的问题。当我复制 module.xml 的 WordPress 示例时,我得到了(注意大引号):

<resource-root path=”postgresql-9.4.1211.jar”/>

... but Wildfly is very picky and needs this (straight quotes):

...但 Wildfly 非常挑剔,需要这个(直引号):

<resource-root path="postgresql-9.4.1211.jar"/>

回答by MTaylorEx

There was a typo in module.xml. The name of the connector JAR listed in module.xml did not match the actual JAR file in modules\system\layers\base\com\mysql\main.

module.xml 中存在拼写错误。module.xml 中列出的连接器 JAR 的名称与 modules\system\layers\base\com\mysql\main 中的实际 JAR 文件不匹配。

回答by tk_

In my case I have missed the mainfolder which module.xml and connector jar file need to be included.

就我而言,我错过了main需要包含 module.xml 和连接器 jar 文件的文件夹。

Earlier it was

早些时候是

JBOSS_HOME\modules\system\layers\base\com\mysql\module.xml

and the correct path should be,(module.xml and jar needed be included inside of main)

正确的路径应该是,(module.xml 和 jar 需要包含在 main 中)

JBOSS_HOME\modules\system\layers\base\com\mysql\main\module.xml

回答by Cagdas Arslan

I know it has been while but that may help for others. The recommended approach is to deploy a driver is using the wildfly console (localhost:9990/console). once you deployed the driver jar then create your DS again by using the console then it will create it automatically in the standalone.xml. Sometimes, when doing those stuffs manually may cause missing tiny details which drive us crazy.

我知道已经有一段时间了,但这可能对其他人有帮助。推荐的方法是使用 wildfly 控制台 (localhost:9990/console) 部署驱动程序。一旦你部署了驱动程序 jar 然后使用控制台再次创建你的 DS 然后它会在 standalone.xml 中自动创建它。有时,手动执行这些操作时可能会丢失一些让我们发疯的微小细节。

回答by frankies

Maybe two solutions for your issue:

也许您的问题有两种解决方案:

  • You forgot the attribute sloton moduleelement in module.xmlfile, e.g.:

    <?xml version="1.0" ?> 
    <module xmlns="urn:jboss:module:1.3" name="org.postgresql" slot="main"> 
        <resources>
            <resource-root path="postgresql-9.4.1212.jar"/>
        </resources> 
        <dependencies>
            <module name="javax.api"/>
            <module name="javax.transaction.api"/>
        </dependencies>
    </module>
    

    add code slot="main"in moduleelement, it will take effect.

  • 你忘了属性slotmodule的元module.xml文件,如:

    <?xml version="1.0" ?> 
    <module xmlns="urn:jboss:module:1.3" name="org.postgresql" slot="main"> 
        <resources>
            <resource-root path="postgresql-9.4.1212.jar"/>
        </resources> 
        <dependencies>
            <module name="javax.api"/>
            <module name="javax.transaction.api"/>
        </dependencies>
    </module>
    

    slot="main"module元素中添加代码,它就会生效。



enjoy it.

好好享受。

回答by yyysylvia

For me, it seems to be a coding problem. Before the tag

对我来说,这似乎是一个编码问题。标签前

<module>
...
</module>

in my module.xml file, there is a mysterious blank, which is not utf-8 or English, causing my failure. After I deleted the blank or changed it to an English one. Everything is ok. Also, I looked for some solutions to this problem. Most of them can be summed to the module.xml file's problem. A name typo or the content coding. Hope it heplful for others.

在我的module.xml文件中,有一个神秘的空白,不是utf-8或英文,导致我失败。在我删除空白或将其更改为英文后。一切都好。另外,我寻找了一些解决此问题的方法。其中大部分都可以归结为module.xml 文件的问题。名称拼写错误或内容编码。希望对其他人有帮助。