@Transactional does not work on method level

前端 未结 2 1493
鱼传尺愫
鱼传尺愫 2021-01-03 02:48

I have a question about Spring 3.2.3 @Transactional annotation. My Service class looks like this:

@Service @Transactional
class InventoryDisclosureBO {

@Aut         


        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-03 03:31

    You cannot call persist() from processDisclosureData() because it belongs to the same class and it will bypass transactional proxy created by Spring for InventoryDisclosureBO. You should call it from other beans to make @Transactional annotations work. When Spring injects a reference to InventoryDisclosureBO bean to other beans it actually injects a reference to InventoryDisclosureBOProxy which contains transactional logic, eg

        class Bean2 {
    
          @Autowire
          private InventoryDisclosureBO idbo;   <-- Spring will inject a proxy here
    
          public void persist(InventoryDisclosureStatus data) {
               idbo.persist(data);     <-- now it will work via proxy
          }
    ...
    

提交回复
热议问题