简体   繁体   English

用于Spring启动微服务的MySQL配置

[英]MySQL configuration for Spring boot micro-services

I am building multiple project using spring boot which are connected to single MySQL instance. 我正在使用spring boot构建多个项目,它们连接到单个MySQL实例。 so I am facing some problems in a transaction. 所以我在交易中遇到了一些问题。

From one spring boot instance when i am updating some records on one table and i am retrieving other records from same table with another spring boot instance its waiting until the transaction completes on first instance then it will fetch the records and return it. 从一个春季启动实例,当我更新一个表上的一些记录,我正在从另一个弹簧启动实例检索同一个表中的其他记录,它等待事务在第一个实例完成,然后它将获取记录并返回它。

i want to retrieve the other records (not updating records) while the table has some records which is updating. 我想检索其他记录(不更新记录),而表有一些正在更新的记录。 So what is the best solution for this and what is the configuration i need to change it in MySQL and spring boot as well ? 那么什么是最好的解决方案是什么,我需要在MySQL和spring boot中更改它的配置是什么?

Accessing single Mysql instance from multiple projects is a common thing. 从多个项目访问单个Mysql实例是很常见的事情。 This won't block your transaction as far as you are not fetching resources which are already in transaction. 只要您没有获取已在事务中的资源,这将不会阻止您的事务。 ie which are updating. 即哪些正在更新。 As when a query fire MySQL will lock that object until transaction completes. 当查询触发MySQL时,将锁定该对象,直到事务完成。

What you need to do is to handle via @Transactional annotation. 您需要做的是通过@Transactional注释来处理。 From javax.transaction.Transactional package at service layer and spring boot will handle it automatically. 从服务层的javax.transaction.Transactional包和spring boot将自动处理它。

It should work!! 它应该工作!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM