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

前端 未结 8 2214
谎友^
谎友^ 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:49

    With Spring 4 it's possible to Self autowired

    @Service
    @Transactional
    public class UserServiceImpl implements UserService{
        @Autowired
        private  UserRepository repository;
    
        @Autowired
        private UserService userService;
    
        @Override
        public void update(int id){
           repository.findOne(id).setName("ffffd");
        }
    
        @Override
        public void save(Users user) {
            repository.save(user);
            userService.update(1);
        }
    }
    

提交回复
热议问题