gpt4 book ai didi

mysql - wildfly 将 mysql 注册为数据源

转载 作者:可可西里 更新时间:2023-11-01 07:48:49 26 4
gpt4 key购买 nike

我一直在尝试将 mysql 配置为 wildfly 中的数据源。我不确定我错过了什么,我在启动时遇到错误。

我在文件夹中有 mysql-connector-java-5.0.8-bin.jar 和 module.xml:“/wildfly-8.1.0.Final/modules/system/layers/base/com/mysql/main”

下面是文件

模块.xml

    <module xmlns="urn:jboss:module:1.1" 
name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.0.8.jar"/>
<!-- Insert resources here -->
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>

独立.xml

  <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 jta="true" jndi-name="java:jboss/datasources/proj" pool-name="proj" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://localhost:3306</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>admin123</password>
</security>
<statement>
<prepared-statement-cache-size>32</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
<drivers>
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>

我已经在 eclipse 中用独立程序测试了 jdbc 连接,它工作正常

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class ConnectSql {
public static void main(String []args){
String userName = "root";
String pass = "admin123";
String url = "jdbc:mysql://localhost/";
String driver ="com.mysql.jdbc.Driver";
String db = "proj";

try{
//registering the driver.
Class.forName(driver);
Connection con = DriverManager.getConnection(url+db,userName,pass);
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select f_name from t_users");
while(rs.next()){
System.out.println("name :"+rs.getString(1));
}


} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch(ClassNotFoundException cnf){
cnf.printStackTrace();
}
}
}

引用以下链接修改module.xml

Wildfly 8.0.0 mysql problems with datasource

这是我启动时的错误日志

02:45:17,169 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("add") failed - address: ([ ("subsystem" => "datasources"), ("data-source" => "proj") ]) - failure description: {"JBAS014771: Services with missing/unavailable dependencies" => [ "jboss.data-source.java:jboss/datasources/proj is missing [jboss.jdbc-driver.mysql]", "jboss.driver-demander.java:jboss/datasources/proj is missing [jboss.jdbc-driver.mysql]" ]} 02:45:17,175 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("add") failed - address: ([ ("subsystem" => "datasources"), ("data-source" => "proj") ]) - failure description: { "JBAS014771: Services with missing/unavailable dependencies" => [ "jboss.data-source.java:jboss/datasources/proj is missing [jboss.jdbc-driver.mysql]", "jboss.driver-demander.java:jboss/datasources/proj is missing [jboss.jdbc-driver.mysql]" ], "JBAS014879: One or more services were unable to start due to one or more indirect dependencies not being available." => { "Services that were unable to start:" => [ "jboss.data-source.reference-factory.proj", "jboss.naming.context.java.jboss.datasources.proj" ], "Services that may be the cause:" => ["jboss.jdbc-driver.mysql"] } }

最佳答案

为了解决 Wildfly 上的 mysql 数据源配置问题,我使用管理控制台添加数据源并对其进行测试。

  1. 如果您登录到 Web 控制台并找到您尝试配置的数据源,请禁用 那一个删除它。 standalone.xml 和 module.xml 重置为原始文件。

    Steps for accessing web console

  2. 配置一个新的数据源:

    名称:mysql
    JNDI:java:jboss/datasources/proj

  3. 点击next然后输入url(我用的是下面的)点击enable然后点击test
    网址:jdbc:mysql://localhost/proj

  4. 测试应该显示成功

  5. 对 standalone.xml 和 module.xml 的更改是自动进行的。

  6. 如果您现在重新启动服务器,它应该可以正常启动,并且您应该能够从您的 Web 项目访问数据库

关于mysql - wildfly 将 mysql 注册为数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24990224/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com