2015-09-04 38 views
0

我有一個Java EE Web應用程序。我正在使用它來管理數據庫中的用戶,以便他們可以登錄。事情是產品所有者想要一個不使用數據庫的登錄選項,我已經做到了。但是現在我在將問題部署到glassfish時遇到問題,因爲在部署glassfish時檢查連接,但是我希望能夠配置它。這個版本我不想使用數據庫連接,但我也想輕鬆地再次啓用它。如何臨時禁用jdb​​c資源/連接池(glassfish-resources.xml)

有沒有人知道這個解決方案?

這是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. 

回答

0

我已經設法通過在「glassfish-resources.xml」中將「jbdc-resouce」設置爲false來執行此操作。並在「persistence.xml」註釋「jta-data-source」這一行。