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
If you need to wrap a private method inside a transaction and don't want to use aspectj, you can use TransactionTemplate.
@Service
public class MyService {
@Autowired
private TransactionTemplate transactionTemplate;
private void process(){
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
processInTransaction();
}
});
}
private void processInTransaction(){
//...
}
}
The answer is no. Please see Spring Reference: Using @Transactional :
The
@Transactional
annotation may be placed before an interface definition, a method on an interface, a class definition, or a public method on a class