如何临时禁用jdb​​c-resource / connection-pool(glassfish-resources.xml)

时间:2015-09-04 08:27:59

标签: java java-ee jdbc glassfish

我有一个Java EE Web应用程序。我使用它来管理数据库中的用户,因此他们可以登录。问题是产品所有者想要一个不使用DB登录的选项,我已经做到了。但是我现在遇到了将此问题部署到glassfish的问题,因为部署glassfish会检查连接,但我希望能够配置它,例如这个构建我不想使用数据库连接,但我也希望能够轻松地再次启用它。

有没有人知道这方面的解决方案?

这是persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="WebApp_PerformancePU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/myWebApp</jta-data-source>
    <class>db.entities.User</class>
    <properties>
        <property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
    </properties>
  </persistence-unit>
</persistence>

这是glassfish-resource.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
  <jdbc-resource enabled="true" jndi-name="jdbc/myWebApp" object-type="user" pool-name="webAppPool">
    <description/>
  </jdbc-resource>
  <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="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" 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="webAppPool" 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="false">
    <property name="URL" value="jdbc:mysql://localhost:3306/webapp?zeroDateTimeBehavior=convertToNull"/>
    <property name="User" value="root"/>
    <property name="Password" value=""/>
  </jdbc-connection-pool>
</resources>

在glassfish上部署时,glassfish说:

Error occurred during deployment: Exception while deploying the app [WebApp] : Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. Error Code: 0. Please see server.log for more details.

1 个答案:

答案 0 :(得分:0)

通过设置&#34; jbdc-resouce&#34;我设法做到了这一点。在&#34;中启用false的glassfish-resources.xml中&#34 ;.并且在&#34; persistence.xml&#34;评论&#34; jta-data-source&#34;线。