Java 添加新的数据源(mysql)wildfly
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27887392/
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
Add new Datasource (mysql) wildfly
提问by Gtopuria
I'm trying to add new datasource mysql jdbc driver to my wildfly server
我正在尝试将新的数据源 mysql jdbc 驱动程序添加到我的 Wildfly 服务器
I created folder wildfly.x.x.x/modules/system/layers/base/com/mysql/main I've got here jdbc jar file and module.xml
我创建了文件夹 wildfly.xxx/modules/system/layers/base/com/mysql/main 我在这里有 jdbc jar 文件和 module.xml
<module xmlns="urn:jboss:module:1.3" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.34-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
then added dataresource code into standalone-full.xml (under datareources tag)
然后将数据资源代码添加到 standalone-full.xml (在 datareources 标签下)
<datasource jndi-name="java:jboss/datasources/MySQLDS" pool-name="MySQLDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/test</connection-url>
<driver>MySQLDriver</driver>
<security>
<user-name>root</user-name>
<password></password>
</security>
</datasource>
but when i go to wildfly control panel http://localhost:9990/console/
dataresource doesnt appear , what did i missed?
但是当我去wildfly控制面板数据http://localhost:9990/console/
资源没有出现时,我错过了什么?
also i'm trying to add it manually from interface i'v got this error
我也试图从界面手动添加它我遇到了这个错误
Unexpected HTTP response: 500
Request
{
"address" => [
("subsystem" => "datasources"),
("data-source" => "mysql")
],
"operation" => "test-connection-in-pool"
}
Response
Internal Server Error
{
"outcome" => "failed",
"failure-description" => "JBAS010440: failed to invoke operation: JBAS010447: Connection is not valid",
"rolled-back" => true
}
采纳答案by Harald Wellmann
Did you add a driver definition? Your datasources
subsystem should look something like this:
您是否添加了驱动程序定义?您的datasources
子系统应如下所示:
<subsystem xmlns="urn:jboss:domain:datasources:2.0">
<datasources>
<datasource jndi-name="java:/jdbc/myds" pool-name="myds" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost/mydb</connection-url>
<driver>mysql</driver>
<security>
<user-name>foo</user-name>
<password>bar</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">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
The driver
element in the data source definition must reference a driver
element by name. The module
attribute must match the name of your MySQL driver module.
该driver
数据源定义元件必须引用driver
由name元素。该module
属性必须与您的 MySQL 驱动程序模块的名称匹配。
回答by Todor Todorov
Also create the database that you will use. Sometimes the reason for this error is that the database is missing.
还要创建您将使用的数据库。有时这个错误的原因是数据库丢失。
回答by Zero
Actually I meet the same problem (I could add the datasources and test connection successfully before) So I'm just confused and I find a way works for me:)
实际上我遇到了同样的问题(我之前可以成功添加数据源并测试连接)所以我很困惑,我找到了一种适合我的方法:)
See my services and I find it stopped,and I started it then tried again,It works well again! Even though your service does not stop, maybe just restart it. I have to say it may not work for you if you never success to connect before,good luck~
查看我的服务,我发现它停止了,我启动它然后再次尝试,它再次运行良好!即使您的服务没有停止,也许只需重新启动它。我不得不说,如果你以前从未成功连接过,它可能对你不起作用,祝你好运~
回答by PVR
There are three waysusing which you can simply create datasource into wildfly
有三种方法使用,你可以简单地创建数据源到wildfly
- Using admin console
- Manually adding into standalone.xml
- Creating datasource file that is xml file.
- 使用管理控制台
- 手动添加到 standalone.xml
- 创建数据源文件,即 xml 文件。
Go to WildFly directory/standalone/deploymentsSimplest way to create datasource xml with following content
转到WildFly 目录/standalone/deployments使用以下内容创建数据源 xml 的最简单方法
<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>