javax.transaction.Transactional vs org.springframework.transaction.annotation.Transactional [英] javax.transaction.Transactional vs org.springframework.transaction.annotation.Transactional
问题描述
我不明白注释 javax.transaction.Transactional
和 org.springframework.transaction.annotation.Transactional
?
是 org.springframework.transaction.annotation.Transactional
< c $ c> javax.transaction.Transactional 或者它们有完全不同的含义?什么时候应该每个人都使用?在DAO中服务层和 javax 中的 @Transactinal
感谢您的回答。
Spring定义了自己的Transactional注释来使Spring bean方法在几年前成为事务性的。
Java EE 7终于做了同样的事情,现在除了EJB方法外,还允许CDI bean方法成为事务性的。所以从Java EE 7开始,它也定义了它自己的Transactional注解(它显然不能重用Spring的注解)。
在Java EE 7应用程序中,使用Java EE注解。
在Spring应用程序中,您将使用Spring注释。
使用是相同的:通知容器(Java EE或Spring)方法是事务性的。
I don't understand what is the actual difference between annotations javax.transaction.Transactional
and org.springframework.transaction.annotation.Transactional
?
Is org.springframework.transaction.annotation.Transactional
an extension of javax.transaction.Transactional
or they have totally different meaning? When should each of them be used? Spring @Transactinal
in service layer and javax in DAO?
Thanks for answering.
Spring has defined its own Transactional annotation to make Spring bean methods transactional, years ago.
Java EE 7 has finally done the same thing and now allows CDI bean methods to be transactional, in addition to EJB methods. So since Java EE 7, it also defines its own Transactional annotation (it obviously can't reuse the Spring one).
In a Java EE 7 application, you'll use the Java EE annotation.
In a Spring application, you'll use the Spring annotation.
Their use is the same: informing the container (Java EE or Spring) that a method is transactional.
这篇关于javax.transaction.Transactional vs org.springframework.transaction.annotation.Transactional的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!