springboot JPA Connection is read-only. Queries leading to data modification are not allowed

本文介绍了解决在Spring Boot应用中使用阿里云MySQL数据库遇到的JPA连接只读问题的方法。通过指定使用阿里Druid数据库连接池,成功解决了数据修改操作受限的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境:springboot、jpa
数据库:阿里云mysql数据库
数据库连接字符串:
这里写图片描述
问题描述:在自己部署的mysql数据库可以正常访问,没有问题,但是切换到阿里mysql数据库上出现JPA Connection is read-only. Queries leading to data modification are not allowed 网上查询了好多,也没有找到解决方法,
application.properties不指定spring.datasource.type值 spring Boot默认的数据源是:org.apache.tomcat.jdbc.pool.DataSource
这里写图片描述
最后解决方法:
在使用阿里云的数据库需要指定type
pom.xml

<!-- DataSource Pool -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.18</version>
        </dependency>

application.properties 使用阿里的数据库连接池

spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值