无法在 JBoss EAP 7.2 中添加 SQL Server 数据源
Posted
技术标签:
【中文标题】无法在 JBoss EAP 7.2 中添加 SQL Server 数据源【英文标题】:Unable to add SQL Server DataSource in JBoss EAP 7.2 【发布时间】:2020-01-20 05:02:28 【问题描述】:我正在尝试通过管理控制台在 JBoss EAP 7.2 中添加一个 SQL Server 数据源。但是,测试连接操作失败。以下是版本详情:
JBoss EAP - 7.2
MSSQL 驱动程序 Jar - mssql-jdbc-6.1.0.jre8.jar
Module.xml:
<module name="com.microsoft.sqlserver" xmlns="urn:jboss:module:1.3">
<resources>
<resource-root path="mssql-jdbc-6.1.0.jre8.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/>
</dependencies>
</module>
模块目录结构: jboss-eap-7.2\modules\system\layers\base\com\microsoft\sqlserver\main
Standalone.xml 数据源和驱动程序配置:
<datasource jndi-name="java:/MSSQLDS" pool-name="MSSQLDS">
<connection-url>jdbc:sqlserver://192.168.XX.XX;DatabaseName=MYTESTDB1</connection-url>
<datasource-class>com.microsoft.sqlserver.jdbc.SQLServerDataSource</datasource-class>
<driver>sqlserver</driver>
<security>
<user-name>mydb_xxxx</user-name>
<password>xxxxxxxx</password>
</security>
</datasource>
<driver name="sqlserver" module="com.microsoft.sqlserver">
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>
<datasource-class>com.microsoft.sqlserver.jdbc.SQLServerDataSource</datasource-class>
</driver>
服务器日志:
13:21:52,267 WARN [org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService$AS7DataSourceDeployer] (MSC service thread 1-5) IJ020020: Connection Properties for DataSource: 'java:/MSSQLDS' is empty, try to use driver-class: 'com.microsoft.sqlserver.jdbc.SQLServerDriver' and connection-url: 'jdbc:sqlserver://192.168.XX.XX;DatabaseName=MYTESTDB1' to connect database
13:21:52,279 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
13:21:52,279 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) WFLYJCA0001: Bound data source [java:/MSSQLDS]
13:21:52,640 INFO [org.wildfly.extension.undertow] (MSC service thread 1-2) WFLYUT0006: Undertow HTTPS listener https listening on 127.0.0.1:8443
13:21:52,803 INFO [org.jboss.ws.common.management] (MSC service thread 1-8) JBWS022052: Starting JBossWS 5.2.4.Final-redhat-00001 (Apache CXF 3.2.5.redhat-00001)
13:21:54,308 INFO [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-7) ISPN000128: Infinispan version: Infinispan 'Estrella Galicia' 9.3.3.Final-redhat-00001
13:21:54,598 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 72) WFLYCLINF0002: Started client-mappings cache from ejb container
13:21:54,792 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
13:21:54,924 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
13:21:54,929 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: JBoss EAP 7.2.0.GA (WildFly Core 6.0.11.Final-redhat-00001) started in 8695ms - Started 477 of 663 services (333 services are lazy, passive or on-demand)
13:22:21,345 WARN [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (External Management Request Threads -- 1) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:345)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:352)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:287)
at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.createConnectionEventListener(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:1326)
at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.getConnection(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:499)
at org.jboss.jca.core.connectionmanager.pool.AbstractPool.internalTestConnection(AbstractPool.java:1067)
at org.jboss.jca.core.connectionmanager.pool.strategy.OnePool.testConnection(OnePool.java:93)
at org.jboss.as.connector.subsystems.common.pool.PoolOperations$TestConnectionInPool.invokeCommandOn(PoolOperations.java:240)
at org.jboss.as.connector.subsystems.common.pool.PoolOperations$1.execute(PoolOperations.java:97)
at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:999)
at org.jboss.as.controller.AbstractOperationContext.processStages(AbstractOperationContext.java:743)
at org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:467)
at org.jboss.as.controller.OperationContextImpl.executeOperation(OperationContextImpl.java:1411)
at org.jboss.as.controller.ModelControllerImpl.internalExecute(ModelControllerImpl.java:423)
at org.jboss.as.controller.ModelControllerImpl.lambda$execute$1(ModelControllerImpl.java:243)
at org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:265)
at org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:231)
at org.jboss.as.controller.ModelControllerImpl.execute(ModelControllerImpl.java:243)
at org.jboss.as.domain.http.server.DomainApiHandler.handleRequest(DomainApiHandler.java:212)
at io.undertow.server.handlers.encoding.EncodingHandler.handleRequest(EncodingHandler.java:72)
at org.jboss.as.domain.http.server.DomainApiCheckHandler.handleRequest(DomainApiCheckHandler.java:93)
at org.jboss.as.domain.http.server.security.ElytronIdentityHandler.lambda$handleRequest$0(ElytronIdentityHandler.java:62)
at org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:289)
at org.wildfly.security.auth.server.SecurityIdentity.runAs(SecurityIdentity.java:246)
at org.jboss.as.controller.AccessAuditContext.doAs(AccessAuditContext.java:254)
at org.jboss.as.controller.AccessAuditContext.doAs(AccessAuditContext.java:225)
at org.jboss.as.domain.http.server.security.ElytronIdentityHandler.handleRequest(ElytronIdentityHandler.java:61)
at io.undertow.server.handlers.BlockingHandler.handleRequest(BlockingHandler.java:56)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:360)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:485)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: no further information. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:206)
at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:257)
at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2385)
at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:567)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1955)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1616)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1447)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:788)
at com.microsoft.sqlserver.jdbc.SQLServerDataSource.getConnectionInternal(SQLServerDataSource.java:719)
at com.microsoft.sqlserver.jdbc.SQLServerDataSource.getConnection(SQLServerDataSource.java:79)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:314)
... 35 more
13:22:21,350 ERROR [org.jboss.as.controller.management-operation] (External Management Request Threads -- 1) WFLYCTL0013: Operation ("test-connection-in-pool") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "MSSQLDS")
]) - failure description: "WFLYJCA0040: failed to invoke operation: WFLYJCA0047: Connection is not valid"
更新 - 即使我已经指定了我的数据库的 IP 地址,JBoss 还是试图连接到 localhost 而不是那个 IP。 我已经验证并排除了任何与网络/防火墙相关的问题。通过示例 Java/SpringBoot 项目,我能够打开到数据库的 JDBC 连接。但是,从 JBoss 创建数据源失败。
【问题讨论】:
日志显示:“到主机 localhost 的 TCP/IP 连接,端口 1433 失败。”检查您的 TCP 连接和相关端口。 嗨 Max,我认为这是一个问题,即使我为我的数据库指定了 IP 地址,JBoss 仍试图连接到 localhost。我注意到日志中的一条语句 - IJ020020:DataSource 的连接属性:'java:/MSSQLDS' 为空,尝试使用驱动程序类:'com.microsoft.sqlserver.jdbc.SQLServerDriver' 不知道为什么它说连接属性即使提供了数据库 URL、驱动程序类、数据源类等所有字段,也为空 我认为 Jboss 不会读取您的 xml,docs says 将配置放在subsystem xmlns="urn:jboss:domain:datasources:4.0"
下的 Datasource Definitions 上
确保在 MSSql Server 中启用了 TCP/IP。检查***.com/questions/2388042/…问题
JDBC connection failed, error: TCP/IP connection to host failed的可能重复
【参考方案1】:
终于找到了解决办法。在添加驱动模块时使用 datasource-class 时 Wildfly 会出现问题。
对于数据源类,需要明确的连接属性,并且“有效地”忽略连接 URL 标记。通过“有效地”忽略,我的意思是 JBoss 错误地认为 connection-url 标记存在并且只是忽略它。
此问题已在问题 - WFLY-6157 和 WFLY-6200 中提出。
【讨论】:
你拯救了我的一天。谢谢。 你能扩展吗?我不明白这是一个答案(我的错,我敢肯定)。我有这个确切的问题【参考方案2】:这有点晚了,但可以在redhat solutions 中找到解决方案。问题是在定义非 XA 数据源时,数据源类已在数据源设置中定义。
所以我所做的是转到管理控制台 > 配置 > 子系统 > 数据源和驱动程序 > 数据源 > > 点击查看。
在属性选项卡上>单击编辑>删除数据源类中的值>保存并重新加载服务器。
现在测试您的连接,应该会成功。
【讨论】:
我可以吻你。但首先我要在红帽停车场等待并击败他们所有的开发人员。【参考方案3】:考虑到 Vaibhav1988 的 cmets 关于“数据源类需要显式连接属性”,在我的情况下,解决方案是在数据源配置下添加以下 2 个属性:
数据库名称=
服务器名称=
在管理控制台中,转到“子系统”->“数据源和驱动程序”->“数据源”,然后单击数据源中的“查看”,转到“连接”选项卡,单击“编辑”并添加属性在“连接属性”字段中。
【讨论】:
【参考方案4】:我的解决方案,编辑文件standalone.xml:
<datasource jndi-name="java:jboss/datasources/SqlServerdb" pool-name="SqlServerdb" statistics-enabled="true">
<datasource-class>com.microsoft.sqlserver.jdbc.SQLServerDataSource</datasource-class>
<connection-property name="databaseName">
DATABASENAME
</connection-property>
<connection-property name="ServerName">
IP(WITHOUT PORT)
</connection-property>
<driver>sqlserver</driver>
<security>
<user-name>USER</user-name>
<password>PASSWORD</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker"/>
<background-validation>true</background-validation>
</validation>
</datasource>
和:
<driver name="sqlserver" module="com.microsoft.sqlserver">
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>
</driver>
【讨论】:
以上是关于无法在 JBoss EAP 7.2 中添加 SQL Server 数据源的主要内容,如果未能解决你的问题,请参考以下文章
javax.jms.JMSException:在向JBoss EAP 7.2中的嵌入式ActiveMQ Artemis发送消息时,未能创建会话工厂。
无法将 Jvisual Vm 与 Jboss EAP 6.1 集成