a transaction control
@Service public class CityServiceImpl implements CityService { @Autowired private CityMapper cityMapper; @Override @Transactional(value = "primaryTxMan", readOnly = true) public List<City> findByState(String state) { return this.cityMapper.findByState(state); } }
@Transcational(readOnly=true) This annotation is generally written on the business class, or on its method, to add transaction control to it. When readOnly=true is added to the parentheses, it will tell the underlying data source that this is a read-only transaction. For JDBC, read-only transactions will have a certain speed optimization .
Two Transactional value
The value here is mainly used to specify different transaction managers; it is mainly used to satisfy the existence of different transaction managers in the same system. For example, in Spring, two transaction managers, txManager1, txManager2, are declared.
The user can then specify a specific txManager as needed based on this parameter.
Then some students will ask under what circumstances will there be multiple transaction managers? For example, in a system that needs to access multiple data sources or multiple databases, multiple transaction managers must be configured.