Glassfish:在应用程序启动时默默忽略不可用的数据源 [英] Glassfish: Silently ignore unavailable data source at application start up

查看:117
本文介绍了Glassfish:在应用程序启动时默默忽略不可用的数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Glassfish 3.1.2上使用JPA 2.0的EJB应用程序(提供者是EclipseLink)。当数据库关闭时,应用程序无法启动,甚至更多:无法部署。这是因为EclipseLink会进行一些初始验证。



有没有办法可以在应用程序被部署并启动后即使数据库关闭?

背景:在调用访问数据库的第一个业务功能之前,资源不可用将不会起作用。从应用程序启动到第一个业务功能调用,都有一个时间窗口,可以启动数据库。



更改 glassfish-resources中的默认值。 xml 为属性 connection-creation-retry-attempts connection-creation-retry-interval-in-seconds of < jdbc-connection-pool> 在某些方面有所帮助,但在启动时仍然会在首次使用时检查数据库的可用性。

来自EclipseLink的

ExceptionHandler 不是我记住的方式:当异常处理程序启动时,EclipseLink已经开始验证过程因此试图连接到数据库。我正在寻找的方式是推迟验证过程本身,直到第一次业务调用。

EclipseLink数据库验证 在第一次使用时执行。但是,这第一次使用很可能是由容器处理的 @PersistanceUnit 注入点。 @PersistanceUnit 注入是在部署时处理的,并且没有什么可以做到的。如果您不希望EclipseLink在部署时进行验证,则需要处理您自己的 EntityManagerFactory



我建议创建一个应用程序上下文侦听器,它可以包含 EntityManagerFactory 的副本,并在卸载/重新部署时执行拆卸。在正常运行期间,只有在需要时才能设置任何内容。以下是我将遵循的基本模式: https://en.wikipedia.org/wiki/Initialization -on-demand_holder_idiom


I have an EJB application which uses JPA 2.0 on Glassfish 3.1.2 (provider is EclipseLink). When the database is down the application does not start and even more: can't be deployed. This is because EclipseLink does some initial verification.

Is there a way that the application can be deloyed and started even if the database is down?

Background: The resource being unavailable comes not into play until the first business function is called which accesses the database. From application startup till the first business function call there is a time window where the database may be started.

Changing the defaults in glassfish-resources.xml for the attributes connection-creation-retry-attempts and connection-creation-retry-interval-in-seconds of <jdbc-connection-pool> helps in some way but does still check the database availabilty at startup not at first use.

ExceptionHandler from EclipseLink is not the way I have in mind: when the exception handler comes into play EclipseLink has already started the verification process and hence has tried to connect to the database. The way I am looking for is to postpone the verfification process itself until the first business call.

解决方案

EclipseLink database verification is performed at the first use. However, this first use is most likely a @PersistanceUnit injection point that is handled by the container. @PersistanceUnit injection is handled at deployment time, and there's nothing you can do to catch that. If you don't want EclipseLink to verify at deployment time, you'll need to handle your own EntityManagerFactory.

I'd recommend creating an application context listener, it can hold a copy of your EntityManagerFactory, and be perform tear down when you undeploy/redeploy. During a normal run you can just not set anything up until it is needed. Here's the basic model I would follow: https://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom

这篇关于Glassfish:在应用程序启动时默默忽略不可用的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆