Spring @Transaction method call by the method within the same class, does not work?

前端 未结 8 2169
谎友^
谎友^ 2020-11-22 05:07

I am new to Spring Transaction. Something that I found really odd, probably I did understand this properly.

I wanted to have a transactional around method level and

8条回答
  •  有刺的猬
    2020-11-22 05:45

    It's a limitation of Spring AOP (dynamic objects and cglib).

    If you configure Spring to use AspectJ to handle the transactions, your code will work.

    The simple and probably best alternative is to refactor your code. For example one class that handles users and one that process each user. Then default transaction handling with Spring AOP will work.


    Configuration tips for handling transactions with AspectJ

    To enable Spring to use AspectJ for transactions, you must set the mode to AspectJ:

    
    

    If you're using Spring with an older version than 3.0, you must also add this to your Spring configuration:

    
        
    
    

提交回复
热议问题