是否有一种方法可以在 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 服务器
来部署应用程序。
最佳答案
EJB 的默认事务性已设置,但您可能可以通过使用 CDI-Beans 来避免使用本地 Ejb。如果它们有点单例或无状态,请将它们定义为 ApplicationScoped、RequestScoped 或 SessionScoped,并在需要时使用 @Inject。
关于java - Ejb全局事务管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57122301/