Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not

Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not

在进行修改数据库的时候出现了这个异常
很明显这个是只读引起的


可是事实上我们的数据账号权限很高,说明不是权限问题,说明是事务问题了
原因:你配置了只读事务
解决办法:

  1. 看下你的service层是否配置@Transactional(readOnly=true)
  2. 如果上面你没有配置的话,那就是spring切面引起的

在spring的配置文件中:

 <aop:config
  <aop:advisor pointcut-ref="servicePointcut" advice-ref="txAdvice"/>
    aop:config>

    
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="get*" propagation="REQUIRED" read-only="true"/>
        <tx:method name="find*" propagation="REQUIRED" read-only="true"/>
        <tx:method name="query*" propagation="REQUIRED" read-only="true"/>
    tx:attributes>

你是不是有类似于这样的,如果你的service方法名称是findpassword的话那么就会被拦截到了,然后就read-only了
所以改一下你的方法名称吧

你可能感兴趣的:(java)