Does Spring @Transactional attribute work on a private method?

后端 未结 8 2160
耶瑟儿~
耶瑟儿~ 2020-11-22 14:03

If I have a @Transactional -annotation on a private method in a Spring bean, does the annotation have any effect?

If the @Transactional annotation is on

8条回答
  •  不要未来只要你来
    2020-11-22 14:35

    The answer your question is no - @Transactional will have no effect if used to annotate private methods. The proxy generator will ignore them.

    This is documented in Spring Manual chapter 10.5.6:

    Method visibility and @Transactional

    When using proxies, you should apply the @Transactional annotation only to methods with public visibility. If you do annotate protected, private or package-visible methods with the @Transactional annotation, no error is raised, but the annotated method does not exhibit the configured transactional settings. Consider the use of AspectJ (see below) if you need to annotate non-public methods.

提交回复
热议问题