2011-11-20 72 views
0

我正在准备J2EE Web应用程序,希望将其作为war文件打包并出售给客户端。每个客户端都会将该软件包部署到他的首选应用程序服务器中,并将他的首选数据源用于该应用程序。使用JNDI资源名进行池化的便携式J2EE应用程序

我想知道什么是最好的便携式的方式来定义到数据源的必要映射。

该应用程序使用EclipseLink JPA持久性提供程序。入口点是一样的东西:

@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描述符。此方法可行,但不能移植到其他App Server并产生连接池属性的重复(已在Application Server中定义)。

回答

1

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

你必须在你的web.xml中创建一个resource-ref条目。

根据应用程序服务器,web.xml中的resource-ref条目将执行。其他人可能需要其他文件。

查看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

+0

是的,这是一点,但我找不到任何例子或补习一下吧,但... – perissf

+0

我只是四处寻找一些样品。 :) http://wiki.eclipse.org/Jetty/Howto/Configure_JNDI_Datasource http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html –

+0

哇!它像一个魅力。比预期容易得多! – perissf

相关问题