【问题标题】:Ejb global transaction managementEjb全局事务管理
【发布时间】:2019-07-20 06:21:53
【问题描述】:

有没有办法在EJB 中的一个“地方”配置事务?我知道我可以使用@TransactionManagement,但它需要将此注释添加到每个bean,默认事务属性是REQUIRED。我想要实现的是在整个项目中禁用事务。我尝试使用@Stereotype 创建自定义注释,但它不能与@Singleton 一起使用。那么就会出现这个错误:

[2019-07-20T08:17:31.918+0200] [Payara 5.191] [SEVERE] [NCLS-CORE-00026] [javax.enterprise.system.core] [tid: _ThreadID=172 _ThreadName=admin-thread-pool::admin-listener(5)] [timeMillis: 1563603451918] [levelValue: 1000] [[
  Exception during lifecycle processing
org.glassfish.deployment.common.DeploymentException: CDI definition failure:WELD-001508: Cannot create an InjectionTarget from [EnhancedAnnotatedTypeImpl] public abstract interface @Stereotype @Singleton @Target @TransactionAttribute @Retention class pl.orangelabs.hod.app.config.NoTransactionComponent as it is an int
erface -- WELD-001508: Cannot create an InjectionTarget from [EnhancedAnnotatedTypeImpl] public abstract interface @Stereotype @Singleton @Target @TransactionAttribute @Retention class pl.orangelabs.hod.app.config.NoTransactionComponent as it is an interface
        at org.jboss.weld.util.InjectionTargets.createNonProducibleInjectionTarget(InjectionTargets.java:82)
        at org.jboss.weld.util.InjectionTargets.createNonProducibleInjectionTarget(InjectionTargets.java:48)
        at org.jboss.weld.manager.InjectionTargetFactoryImpl.chooseInjectionTarget(InjectionTargetFactoryImpl.java:126)
        at org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:88)

我正在使用Payara server 来部署应用程序。

【问题讨论】:

    标签: java jakarta-ee transactions ejb payara


    【解决方案1】:

    EJB 的默认事务性已设置,但您可能可以通过使用 CDI-Bean 来避免使用本地 Ejb。如果它们有点单例或无状态,请定义它们 ApplicationScoped、RequestScoped 或 SessionScoped,并在需要它们的地方使用 @Inject。

    【讨论】:

      猜你喜欢
      • 2017-03-29
      • 2020-04-10
      • 2012-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-25
      • 1970-01-01
      相关资源
      最近更新 更多