Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jdbc 防止WildFly过早解除数据源绑定_Jdbc_Wildfly_Datasource - Fatal编程技术网

Jdbc 防止WildFly过早解除数据源绑定

Jdbc 防止WildFly过早解除数据源绑定,jdbc,wildfly,datasource,Jdbc,Wildfly,Datasource,我在一个WildFly实例中有两个Web应用程序 两者都使用各自的数据源—每个都在standalone.xml中定义。定义看起来完全相同: <datasource jndi-name="java:/jdbc/ds-a" pool-name="pool-a" enabled="true" use-java-context="true"> ... </datasource> <da

我在一个WildFly实例中有两个Web应用程序

两者都使用各自的数据源—每个都在standalone.xml中定义。定义看起来完全相同:

<datasource jndi-name="java:/jdbc/ds-a" pool-name="pool-a" enabled="true" use-java-context="true">
    ...
</datasource>

<datasource jndi-name="java:/jdbc/ds-b" pool-name="pool-b" enabled="true" use-java-context="true">
    ...
</datasource>
一切正常,但在关机期间,两个Web应用程序都在执行一些清理任务。虽然webapp A在关机期间仍然能够访问其数据源,但webapp B的数据源已经关闭

这是日志的一个示例:

[org.jboss.as.server] (Management Triggered Shutdown) WFLYSRV0241: Shutting down in response to management operation 'shutdown'
[org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) WFLYJCA0010: Unbound data source [java:/jdbc/ds-b]
[org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 135) IJ000615: Destroying active connection in pool: pool-b (org.jboss.jca.adapters.jdbc.local.LocalManagedConnection@...)
[org.hibernate.util.JDBCExceptionReporter] (webappb/scheduler_dispatch-3) javax.resource.ResourceException: IJ000470: You are trying to use a connection factory that has been shut down: java:/jdbc/ds-b

...

[org.jboss.as.jpa] (ServerService Thread Pool -- 139) WFLYJPA0011: Stopping Persistence Unit (phase 1 of 2) Service 'webappa.war#database'
[org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-6) WFLYJCA0010: Unbound data source [java:/jdbc/ds-a]
[org.jboss.as.server.deployment] (MSC service thread 1-4) WFLYSRV0028: Stopped deployment webappa.war (runtime-name: webappa.war) in 822ms

... many "javax.resource.ResourceException: IJ000470: You are trying to use a connection factory that has been shut down: java:/jdbc/ds-b" ....

[org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) WFLYJCA0010: Unbound data source [java:jboss/datasources/ExampleDS]
[org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-7) WFLYJCA0019: Stopped Driver service with driver-name = h2
[org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 161) WFLYCLINF0003: Stopped http-remoting-connector cache from ejb container
[org.infinispan.manager.DefaultCacheManager] (ServerService Thread Pool -- 161) Stopping cache manager null on null
[org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0019: Host default-host stopping
[org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0008: Undertow HTTP listener default suspending
[org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0007: Undertow HTTP listener default stopped, was bound to 127.0.0.1:8080
[org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0008: Undertow HTTPS listener https suspending
[org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0007: Undertow HTTPS listener https stopped, was bound to 127.0.0.1:8443
[org.wildfly.extension.undertow] (MSC service thread 1-7) WFLYUT0004: Undertow 2.2.3.Final stopping
[org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0028: Stopped deployment webappb.war (runtime-name: webappb.war) in 72112ms
如您所见,数据源ds-b将立即解除绑定,而WildFly将在数据源ds-A解除绑定之前等待A的持久性单元关闭


如何防止WildFly在webapp-b解除部署之前解除数据源的绑定?

您应该将此依赖关系告知WildFly,并在webapp b的
web.xml
中放置
resource ref


然后,您可以使用
jdbc/my db
jdbc/ds-b

查找数据源。也许您应该告诉WildFly这个依赖关系,并在您的web.xml中添加一个资源引用。这是一个很好的主意,它已经帮了很多忙。如果你加上这个作为回答,我会补充一些额外的细节。
DataSource ds = context.lookup("jdbc/ds-b")
[org.jboss.as.server] (Management Triggered Shutdown) WFLYSRV0241: Shutting down in response to management operation 'shutdown'
[org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) WFLYJCA0010: Unbound data source [java:/jdbc/ds-b]
[org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 135) IJ000615: Destroying active connection in pool: pool-b (org.jboss.jca.adapters.jdbc.local.LocalManagedConnection@...)
[org.hibernate.util.JDBCExceptionReporter] (webappb/scheduler_dispatch-3) javax.resource.ResourceException: IJ000470: You are trying to use a connection factory that has been shut down: java:/jdbc/ds-b

...

[org.jboss.as.jpa] (ServerService Thread Pool -- 139) WFLYJPA0011: Stopping Persistence Unit (phase 1 of 2) Service 'webappa.war#database'
[org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-6) WFLYJCA0010: Unbound data source [java:/jdbc/ds-a]
[org.jboss.as.server.deployment] (MSC service thread 1-4) WFLYSRV0028: Stopped deployment webappa.war (runtime-name: webappa.war) in 822ms

... many "javax.resource.ResourceException: IJ000470: You are trying to use a connection factory that has been shut down: java:/jdbc/ds-b" ....

[org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) WFLYJCA0010: Unbound data source [java:jboss/datasources/ExampleDS]
[org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-7) WFLYJCA0019: Stopped Driver service with driver-name = h2
[org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 161) WFLYCLINF0003: Stopped http-remoting-connector cache from ejb container
[org.infinispan.manager.DefaultCacheManager] (ServerService Thread Pool -- 161) Stopping cache manager null on null
[org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0019: Host default-host stopping
[org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0008: Undertow HTTP listener default suspending
[org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0007: Undertow HTTP listener default stopped, was bound to 127.0.0.1:8080
[org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0008: Undertow HTTPS listener https suspending
[org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0007: Undertow HTTPS listener https stopped, was bound to 127.0.0.1:8443
[org.wildfly.extension.undertow] (MSC service thread 1-7) WFLYUT0004: Undertow 2.2.3.Final stopping
[org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0028: Stopped deployment webappb.war (runtime-name: webappb.war) in 72112ms
<web-app>
    ...
    <resource-ref>
        <description>My database reference</description>
        <res-ref-name>jdbc/my-db</res-ref-name>
    </resource-ref>
</web-app>
<jboss-web>
    ...
    <resource-ref>
        <res-ref-name>jdbc/my-db</res-ref-name>
        <jndi-name>java:/jdbc/ds-b</jndi-name>
    </resource-ref>
</jboss-web>