我在运行 MySQL 数据库的同一台服务器上运行 glassfish。当我尝试通过管理控制台部署 Web 应用程序时,我收到以下错误: 部署期间发生错误:准备应用程序时出现异常:资源无效:solardbdatasource__pm。有关详细信息,请参阅 server.log。
但是,我能够从另一台计算机运行 Web 应用程序并远程连接到数据库,只有当我尝试将应用程序部署在与数据库相同的服务器上时,我才会收到错误消息。我的 glassfish-resources.xml 用于我的工作远程连接:
<resources>
<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="mysql_solardb_rootPool"
non-transactional-connections="false" pool-resize-quantity="2"
res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1"
steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="serverName" value="192.168.1.113"/>
<property name="portNumber" value="3306"/>
<property name="databaseName" value="solardb"/>
<property name="User" value="root"/>
<property name="Password" value="password"/>
<property name="URL" value="jdbc:mysql://192.168.1.113:3306/solardb?zeroDateTimeBehavior=convertToNull"/>
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="solardbdatasource" object-type="user" pool-name="mysql_solardb_rootPool"/>
当我尝试在服务器上部署它时,我将 '192.168.1.113' 更改为 '127.0.0.1'(localhost) 无济于事。我的persistance.xml:
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="solar-decathlonPU" transaction-type="JTA">
<jta-data-source>solardbdatasource</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>