为什么Java JDBC连接池需要在部署时进行验证?
我在部署我的Java EE应用(.ear文件)时遇到了问题。这个问题与我在应用中使用的JDBC连接池有关。我无法将应用部署到服务器上。控制台显示以下内容:
WARNING: RAR5038:Unexpected exception while creating resource for pool oracle_PROD_Pool. Exception : javax.resource.spi.ResourceAllocationException: Connection could not be allocated because: Wyjątek we-wy: The Network Adapter could not establish the connection
WARNING: RAR5117 : Failed to obtain/create connection from connection pool [ oracle_PROD_Pool ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: Wyjątek we-wy: The Network Adapter could not establish the connection
WARNING: RAR5114 : Error allocating connection : [Error in allocating a connection. Cause: Connection could not be allocated because: Wyjątek we-wy: The Network Adapter could not establish the connection]
SEVERE: Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: Wyjątek we-wy: The Network Adapter could not establish the connection
Error Code: 0...
然后我得到了SQLException堆栈跟踪,部署失败了。
我知道这是因为数据库服务器无法访问,无法创建连接,但我仍想部署应用程序并在“应用使用时间”时获取SQLException。 这是我的jdbc连接池定义:
<jdbc-connection-pool allow-non-component-callers="false"
associate-with-thread="false"
connection-creation-retry-attempts="0"
connection-creation-retry-interval-in-seconds="10"
connection-leak-reclaim="false"
connection-leak-timeout-in-seconds="0"
connection-validation-method="auto-commit"
datasource-classname="oracle.jdbc.pool.OracleConnectionPoolDataSource"
fail-all-connections="true"
idle-timeout-in-seconds="300"
is-connection-validation-required="true"
is-isolation-level-guaranteed="true"
lazy-connection-association="false"
lazy-connection-enlistment="false"
match-connections="false"
max-connection-usage-count="0"
max-pool-size="32"
max-wait-time-in-millis="60000"
name="oracle_PROD_Pool"
non-transactional-connections="false"
pool-resize-quantity="2"
res-type="javax.sql.ConnectionPoolDataSource"
statement-timeout-in-seconds="-1"
steady-pool-size="8"
validate-atmost-once-period-in-seconds="0"
wrap-jdbc-objects="true">
<property name="User" value="user"/>
<property name="DatabaseName" value="PROD"/>
<property name="Password" value="pass"/>
<property name="DataSourceName" value="OracleConnectionPoolDataSource"/>
<property name="ServerName" value="172.27.0.101"/>
<property name="DriverType" value="thin"/>
<property name="ExplicitCachingEnabled" value="false"/>
<property name="MaxStatements" value="0"/>
<property name="NetworkProtocol" value="tcp"/>
<property name="ImplicitCachingEnabled" value="false"/>
<property name="URL" value="jdbc:oracle:thin:@172.27.0.101:1521:PROD"/>
<property name="PortNumber" value="1521"/>
<property name="LoginTimeout" value="0"/>
</jdbc-connection-pool>
以及相关的 JDBC 资源:
<jdbc-resource enabled="true" jndi-name="jdbc/oraclePROD" object-type="user" pool-name="oracle_PROD_Pool"/>
这个问题发生在我迁移到新版本的GlassFish服务器3.1.2.2之后。早先我一直使用GlassFish 3.1.1(build 12),部署时没有问题,我的意思是连接池在部署时没有被检查和填充,而是在我的应用程序尝试执行从所述jdbc连接池获取数据的代码时才占用。 我对此有点沮丧。有没有办法在部署时禁用创建和填充jdbc连接池?非常感谢任何帮助。--Jaroslaw