Maven 嵌入式 Glassfish 插件 - 数据源和 JDBC 驱动程序
我正在尝试遵循 这种 方法为嵌入式 glassfish 创建数据源。本教程和我的代码之间唯一显着的区别是我使用官方 Maven 插件和 embedded-glassfish:run
目标运行服务器。
pom 文件中存在 JDBC 驱动程序的依赖项:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.155</version>
</dependency>
而我的 glassfish-resources.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/myDatasource" object-type="user" pool-name="connectionPool">
<description/>
</jdbc-resource>
<jdbc-connection-pool datasource-classname="org.h2.jdbcx.JdbcDataSource" name="connectionPool" res-type="javax.sql.DataSource">
<property name="URL" value="jdbc:h2:~/Documents/Projetos/DBs/h2/glassfish/glassfish;AUTO_SERVER=TRUE;MVCC=TRUE"/>
<property name="User" value="sa"/>
<property name="Password" value=""/>
<property name="driverClass" value="org.h2.Driver"/>
</jdbc-connection-pool>
</resources>
它使用本地 glassfish 服务器运行良好。但嵌入式实例并不幸运:
2011年3月6日 19:26:31 com.sun.enterprise.v3.server.ApplicationLifecycle 部署 GRAVE:无效资源: jdbc/myDatasource_pm java.lang.RuntimeException:无效 资源:jdbc/myDatasource_pm at com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:539) 在 com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:468) 在 org.glassfish.persistence.common.PersistenceHelper.lookupPMResource(PersistenceHelper.java:63) 在 org.glassfish.persistence.jpa.ProviderContainerContractInfoBase.lookupDataSource(ProviderContainerContractInfoBase.java:71) 在
...有人能解释一下吗?
I'm trying to follow this approach to create a datasource for embedded glassfish. The only significant difference between the tutorial and my code is that I'm running the server using the official maven plugin and the embedded-glassfish:run
goal.
There is a dependency for the JDBC driver in the pom file:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.155</version>
</dependency>
And my glassfish-resources.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/myDatasource" object-type="user" pool-name="connectionPool">
<description/>
</jdbc-resource>
<jdbc-connection-pool datasource-classname="org.h2.jdbcx.JdbcDataSource" name="connectionPool" res-type="javax.sql.DataSource">
<property name="URL" value="jdbc:h2:~/Documents/Projetos/DBs/h2/glassfish/glassfish;AUTO_SERVER=TRUE;MVCC=TRUE"/>
<property name="User" value="sa"/>
<property name="Password" value=""/>
<property name="driverClass" value="org.h2.Driver"/>
</jdbc-connection-pool>
</resources>
It runs fine using a local glassfish server. But no lucky with the embedded instance:
03/06/2011 19:26:31
com.sun.enterprise.v3.server.ApplicationLifecycle
deploy GRAVE: Invalid resource :
jdbc/myDatasource_pm
java.lang.RuntimeException: Invalid
resource : jdbc/myDatasource_pm at
com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:539)
at
com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:468)
at
org.glassfish.persistence.common.PersistenceHelper.lookupPMResource(PersistenceHelper.java:63)
at
org.glassfish.persistence.jpa.ProviderContainerContractInfoBase.lookupDataSource(ProviderContainerContractInfoBase.java:71)
at
I'm clueless... Can anyone shed some light on it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了。毕竟它与 glassfish-resources.xml 无关。 jdbc 资源已正确创建并绑定到
java:app/jdbc/myDatasource
。我的持久性单元(由 Netbeans 生成)正在寻找
jdbc/myDatasource
但没有找到任何内容。我最终更改了我的持久性单元以指向应用程序名称空间:
另一个选择是使用
embedded-glassfish:admin
目标来部署具有非标准名称的全局资源(以便我可以使用 <代码>jdbc/myDatasource)。但采用标准似乎是最好的方法。这个主题非常有帮助。
Figured it out. It had nothing to do with
glassfish-resources.xml
after all. The jdbc resource was properly created and bound tojava:app/jdbc/myDatasource
.My persistence unit (generated by Netbeans) was looking for
jdbc/myDatasource
and not finding anything.I ended up changing my persistence unit to point to the application namespace:
Another option would be using the
embedded-glassfish:admin
goal to deploy a global resource with non-standard name (so that I could usejdbc/myDatasource
). But going standard seemed like the best approach.This topic was very helpful.