【问题标题】:Make portable J2EE applications using JNDI resource names for pooling使用 JNDI 资源名称进行池化制作可移植 J2EE 应用程序
【发布时间】:2012-01-02 06:50:24
【问题描述】:

我正在准备一个 J2EE Web 应用程序,希望将其打包并以war 文件的形式出售给客户。每个客户都会将包部署到他喜欢的应用服务器中,并将应用与他喜欢的数据源一起使用。

我想知道定义到数据源的必要映射的最佳可移植方式是什么。

应用程序使用 EclipseLink JPA Persistence Provider。入口点类似于:

@PersistenceContext(unitName = "myPersistenceUnit")
private EntityManager em;

myPersistenceUnitpersistence.xml中的描述如下:

  <persistence-unit name="myPersistenceUnit" transaction-type="JTA">
    <jta-data-source>myDataSource</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>

现在我的猜测是我需要以某种方式将myDataSource 映射到应用程序服务器 JNDI 资源名称,但我不知道该怎么做。如果我在 GlassFish 服务器上使用 NetBeans 自动生成的代码,它会为此目的创建 glassfish-resources.xml 描述符。这种方法有效,但不能移植到其他应用服务器,并且会产生连接池属性的副本(已在应用服务器中定义)。

【问题讨论】:

    标签: jakarta-ee datasource jndi connection-pooling portability


    【解决方案1】:

    使用相关的 JNDI 映射并将它们链接到您的 web.xml。

    您必须在 web.xml 中创建一个资源引用条目。

    根据应用程序服务器,web.xml 中的资源引用条目会起作用。其他人可能需要其他文件。

    在此处查看 web.xml 部分的示例。

    http://download.oracle.com/docs/cd/E12840_01/wls/docs103/webapp/configureresources.html http://wiki.eclipse.org/Jetty/Howto/Configure_JNDI_Datasource http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-16
    • 2014-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多