我在运行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>
答案 0 :(得分:0)
我的问题似乎是单独下载glassfish并不附带mysql连接器。另外,我需要通过管理员控制台手动配置jdbc连接池。我遇到的最后一个问题是'URL'属性,默认设置连接池时实际上有两个:'Url'和'URL',后者是我想要的。