Marking a non-public method `@Async` or `@Transactional` is misleading because Spring does not recognize non-public methods, and so makes no provision for their proper invocation.
Therefore marking a private method, for instance, @Transactional can only result in a runtime error or exception if the method is annotated as @Transactional.
Note that this action alone does not resolve the issue of direct instance calls from within the same class (see rule S6809), but it is a required precondition to fix it.
- https://www.baeldung.com/spring-async[Baeldung - How To Do @Async in Spring]
- https://stackoverflow.com/questions/22561775/spring-async-ignored[Stack Overflow - Spring @Async ignored]
- https://stackoverflow.com/questions/4396284/does-spring-transactional-attribute-work-on-a-private-method[Stack Overflow - Does Spring @Transactional attribute work on a private method?]
=== on 27 Nov 2018, 13:06:43 Semyon Danilov wrote:
\[~ann.campbell.2] Actually, any method can be Transactional if you're using AspectJ compiler, it's stated in the docs https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/html/transaction.html[here]. The excerpt:
----
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.