gpt4 book ai didi

Spring boot微服务的MySQL配置

转载 作者:行者123 更新时间:2023-11-29 15:55:54 24 4
gpt4 key购买 nike

我正在使用 Spring Boot 构建多个项目,这些项目连接到单个 MySQL 实例。所以我在交易中遇到了一些问题。

从一个 Spring Boot 实例中,当我更新一个表上的一些记录,并且我正在使用另一个 Spring Boot 实例从同一个表中检索其他记录时,它会等待事务在第一个实例上完成,然后它将获取记录并返回它。

当表中有一些正在更新的记录时,我想检索其他记录(而不是更新记录)。那么最好的解决方案是什么?我需要在 MySQL 和 Spring Boot 中更改它的配置是什么?

最佳答案

从多个项目访问单个 Mysql 实例是很常见的事情。只要您不获取已在事务中的资源,这就不会阻止您的事务。即正在更新。当查询触发时,MySQL 将锁定该对象,直到事务完成。

What you need to do is to handle via @Transactional annotation. From javax.transaction.Transactional package at service layer and spring boot will handle it automatically.

应该可以用!!

关于Spring boot微服务的MySQL配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56461930/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com