在所有供应商都能使用的persistence.xml的jta-data-source中放入什么? [英] What to put into jta-data-source of persistence.xml that works on all vendors?

查看:588
本文介绍了在所有供应商都能使用的persistence.xml的jta-data-source中放入什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似于要将什么放入jta-data -passion of persistence.xml?如何将jpa数据源映射到WildFly?



然而,我正在寻求一些适用于所有供应商的产品,或者至少可以使用WildFly,Glassfish / Payara,WebSphere Application Server classic,WebSphere Application服务器自由,TomEE。我不在寻找可以在Java SE单元测试中工作的东西。



到目前为止,我发现 java:comp / env / jdbc / xxx 可在WebSphere Application Server和TomEE中使用。有一个映射练习(这是预期的)来让它工作,但我无法在GlassFish / Payara和JBoss / WildFly上工作。



更具体地说,我没有希望使用默认数据源,因为对于我的场景,我实际上正在处理两个不同的数据源。例如。用于参考数据,另一个用于事务处理。

解决方案

如果您想使用适用于所有服务器的相同JNDI名称,最好使用资源引用, 什么是web.xml中的资源引用?



基本上,您可以定义一个任意的JNDI名称(最好不带任何 java:comp >前缀或类似名称,就像myDatasource),然后将其映射到目标服务器提供的具体JNDI名称。如果服务器无法直接使用JNDI,则需要为每个服务器定义服务器特定的描述符(例如glassfish用于GlassFish / Payara的-web.xml,用于WildFly的jboss-web.xml,用于WebSphere Classic和Liberty的ibm-web-bnd.xml)。 TomEE似乎支持没有任何前缀的引用,所以它应该能够配置数据源没有任何额外的映射,如果你选择一个没有前缀的名字。


Similar to What to put into jta-data-source of persistence.xml? and How to map jpa datasources in WildFly?

However, I am asking for something that would work on all vendors or at least WildFly, Glassfish/Payara, WebSphere Application Server classic, WebSphere Application Server Liberty, TomEE. I am not looking for something that works in a Java SE Unit test.

So far I found that java:comp/env/jdbc/xxx works in WebSphere Application Server and TomEE. There's a mapping exercise (which is expected) to get it working but I cannot get the same to work on GlassFish/Payara and JBoss/WildFly.

More specifically I do not wish to use default data source because for my scenario I am actually working on two different data sources. E.g. for reference data and another for transactional.

解决方案

If you want to use the same JNDI name that works on all servers, it's best to use resource references, as explained in What is resource-ref in web.xml used for?

Basically, you would define an arbitrary JNDI name (ideally without any java:comp prefix or similar, just something like "myDatasource") and then map it to the concrete JNDI name provided by the target server.You would need to define a server-specific descriptor for each server with the mapping the if the server cannot use the JNDI directly (e.g. glassfish-web.xml for GlassFish/Payara, jboss-web.xml for WildFly, ibm-web-bnd.xml for WebSphere Classic and Liberty). TomEE seems to support references without any prefix, so it should be able to configure a datasource without any additional mapping if you choose a name without a prefix.

这篇关于在所有供应商都能使用的persistence.xml的jta-data-source中放入什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆