我正在使用Spring Boot、Spring Rest Controller和Spring Data JPA。如果我不指定@Transaction,那么记录仍将被创建,但我想了解它是如何发生的。我的理解是,Spring默认添加具有默认参数的事务,但不确定它是在Service层还是Repository中添加。
public interface CustomerRepository extends CrudRepository<Customer, Long> {
List<Customer> findByLastName(String lastName);
}
@Service
public class CustomerServiceImpl implements CustomerService> {
List<Customer> findByLastName(String lastName){
//read operation
}
// What will happen if @Transaction is missing. How record get's created without the annotation
public Customer insert(Customer customer){
// insert operations
}
}