为什么我们在使用@TransactionAttribute 的时候还要使用@Stateless? EJB

Why do we use @Stateless when using @TransactionAttribute? EJB

我想知道为什么我们在使用 TransactionAttributeType 时使用无状态注释,如下所示:

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) 
@Stateless
public class Controller {

感谢任何帮助,谢谢!

@Stateless 确定 bean 的类型(不与客户端保持对话状态的 bean)。 @TransactionAttribute 决定了处理事务的方式。在您的示例中,bean 在调用结束后不会保持 client-specific 状态。但是当你选择 REQUIRES_NEW 时,它总是会为每个方法调用创建一个新的事务(与默认的 REQUIRED 相反,当可以使用现有事务时,如果它不存在,它将由容器创建)。