简体   繁体   English

独立的CDI +没有JNDI的JTA

[英]StandAlone CDI + JTA Without JNDI

I am using CDI + DeltaSpike + Camel in a standalone app. 我在独立应用程序中使用CDI + DeltaSpike + Camel。

Here is my current setup : 这是我当前的设置:

persistence.xml persistence.xml

<persistence 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"
         version="2.0">
<persistence-unit name="primary" transaction-type="RESOURCE_LOCAL">
    <shared-cache-mode>DISABLE_SELECTIVE</shared-cache-mode>
</persistence-unit>

Custom properties on EntityManagerFactoryProducer: EntityManagerFactoryProducer上的自定义属性:

properties.put("hibernate.connection.provider_class", "org.example.HikariConnectionProvider");

I'm using DeltaSpike JPA Transaction with ( https://deltaspike.apache.org/documentation/jpa.html ): 我正在将DeltaSpike JPA Transaction与( https://deltaspike.apache.org/documentation/jpa.html )配合使用:

  • org.apache.deltaspike.jpa.api.transaction.TransactionScoped; org.apache.deltaspike.jpa.api.transaction.TransactionScoped;
  • org.apache.deltaspike.jpa.api.transaction.Transactional; org.apache.deltaspike.jpa.api.transaction.Transactional;

I would like to use Infinispan to sync my app caches. 我想使用Infinispan同步我的应用程序缓存。 According to Infinispan doc: 根据Infinispan doc:

"It is highly recommended that Hibernate is configured with JTA transactions" “强烈建议为Hibernate配置JTA事务”

How can I use JTA transactions ? 如何使用JTA交易? I tried to change "RESOURCE_LOCAL" to "JTA" but I don't understand what am I supposed to configure for : 我试图将“ RESOURCE_LOCAL”更改为“ JTA”,但我不知道该为什么配置:

  • hibernate.transaction.factory_class hibernate.transaction.factory_class
  • hibernate.transaction.jta.platform hibernate.transaction.jta.platform

I am not using JNDI, and I am not in an application server. 我没有使用JNDI,并且不在应用程序服务器中。

Also, I would like to use @javax.transaction.Transactional instead of DeltaSpike. 另外,我想使用@ javax.transaction.Transactional而不是DeltaSpike。

Essentially, you are asking how to use most Java EE features without using a Java EE container. 本质上,您在询问如何在不使用Java EE容器的情况下使用大多数Java EE功能。

Of course, there are JTA implementations like Atomikos you can embed in a "standalone" application. 当然,您可以将JTA实现(例如Atomikos)嵌入“独立”应用程序中。

On the other hand, it might be a lot easier to start with a full-blown Java EE environment and then ignore or exclude anything you don't need. 另一方面,从功能完善的Java EE环境开始,然后忽略或排除不需要的内容可能会容易得多。

App servers are rather lightweight these days, and if a self-contained executable is a must-have for you, then have a look at WildFly Swarm or Payara Micro. 如今,应用程序服务器非常轻巧,如果您需要一个自包含的可执行文件,请查看WildFly Swarm或Payara Micro。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM