通过CLI配置时,Wildfly数据源启用在运行时不工作



我们正在从jboss Eap 6.4迁移到Wildfly。在迁移期间,作为应用程序安装的一部分,我们将在domain.xml中配置不同的xa-数据源。此配置将通过jboss-cli.sh完成。

配置数据源后,在部署ear时(特别是在*-ejb.jar中),我们得到一个错误,说'持久单元'不可用,并且部署被回滚。

日志显示如下:

WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.persistenceunit."xxyy.ear/xxyy-ejb.jar#xxyyDBUnit" is missing [jboss.naming.context.java.jboss.datasources.xxyyDS]"]

重新启动jboss服务后,相同的部署工作正常。因此,我们认为在domain.xml中配置的数据源没有被激活或启用(尽管我们已经为xa-数据源设置了属性'enabled=true')。在jboss中添加xa-datasource时,我们可以看到以下警告:

2021-09-21 16:57:48,308 INFO [org.jboss.as.connector] (Host Controller Service Threads - 8) WFLYJCA0093: The 'enable' operation is deprecated. Use of the 'add' or 'remove' operations is preferred, or if required the 'write-attribute' operation can used to set the deprecated 'enabled' attribute

有了这个警告,我们知道启用/禁用操作已经在jboss脚本中被删除了。我们是否可以在不重启jboss服务的情况下在运行时启用它?下面是我们用来在wildfly中创建xa-datasource的命令。

/profile=full-ha/subsystem=datasources/xa-data-source=xxyyDS:add(use-java-context=true,use-ccm=false,driver-name=com.mysql,transaction-isolation=TRANSACTION_READ_COMMITTED,min-pool-size=15,max-pool-size=150,pool-prefill=true,flush-strategy=IdleConnections,valid-connection-checker-class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker",stale-connection-checker-class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker",exception-sorter-class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter",set-tx-query-timeout=true,blocking-timeout-wait-millis=5000,idle-timeout-minutes=1,query-timeout=300,prepared-statements-cache-size=100,share-prepared-statements=true,jndi-name="java:jboss/datasources/xxyyDS",user-name=jboss,password="${VAULT::ds_MySqlDS::password::1}")
/profile=full-ha/subsystem=datasources/xa-data-source=xxyyDS/xa-datasource-properties=DatabaseName:add(value=xxyy_db)
/profile=full-ha/subsystem=datasources/xa-data-source=xxyyDS/xa-datasource-properties=ServerName:add(value=xx-cluster)
/profile=full-ha/subsystem=datasources/xa-data-source=xxyyDS/xa-datasource-properties=AutoReconnectForPools:add(value=true)
/profile=full-ha/subsystem=datasources/xa-data-source=xxyyDS/xa-datasource-properties=AutoReconnect:add(value=true)
/profile=full-ha/subsystem=datasources/xa-data-source=xxyyDS/xa-datasource-properties=useSSL:add(value=false)
/profile=full-ha/subsystem=datasources/xa-data-source=xxyyDS:enable

任何关于如何在运行时启用xa-datasource的输入都会对我们有所帮助。

您可以通过CLI启用数据源:

/subsystem=datasources/xa-data-source=xxyyDS:write-attribute(name=enabled,value=true)

可能需要重新加载:

:reload

经过多次尝试和错误的方法,我们发现在添加数据源时默认将处于启用状态。因此,在添加数据源时不需要显式地执行enable。

因此我们从cli列表中删除了下面的行。

/profile = full-ha/子系统=数据源/xa-data-source = xxyyDS:使

在删除行之后,通过CLI配置数据源和部署ear进行得很好,没有任何问题。张贴这个解决方案,因为它将有助于其他人面临类似的问题。

最后,我们的数据源cli将如下所示。

/profile = =数据源full-ha/子系统/xa-data-source = xxyyDS: add (use-java-context = true, use-ccm = false,车手名= com.mysql事务隔离= TRANSACTION_READ_COMMITTED最小池大小= 15,max-pool-size = 150, pool-prefill = true, flush-strategy = IdleConnections valid-connection-checker-class-name ="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker", stale-connection-checker-class-name ="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker" exception-sorter-class-name ="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter" set-tx-query-timeout = true, blocking-timeout-wait-millis = 5000, idle-timeout-minutes = 1, query-timeout = 300, prepared-statements-cache-size = 100, share-prepared-statements = true, jndi名称="java: jboss/数据源/xxyyDS"用户名= jboss,密码="${库::ds_MySqlDS::密码::1}")/profile = full-ha/子系统=数据源/xa-data-source = xxyyDS/xa-datasource-properties =数据库名:加(值= xxyy_db)/profile = =数据源/xa-data-source = xxyyDS full-ha/子系统/xa-datasource-properties = ServerName:加(值= xx-cluster)/profile = full-ha/子系统=数据源/xa-data-source = xxyyDS/xa-datasource-properties = AutoReconnectForPools:加(值= true)/profile = full-ha/子系统=数据源/xa-data-source = xxyyDS/xa-datasource-properties = AutoReconnect:加(值= true)/profile = full-ha/子系统=数据源/xa-data-source = xxyyDS/xa-datasource-properties = useSSL:加(值= false)

相关内容

最新更新