標籤:
昨天做項目時,寫了個方法,程式突然報了Connection is readonly. Queries leading to data modification are not allowed調了程式半天,最後才發現是自己在spring設定檔中增加了事務.把方法寫成了大寫開頭了,但是spring配置是以小寫開頭
代碼如下:
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" ref="transactionManager" /> <property name="transactionAttributes"> <props> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="set*">PROPAGATION_REQUIRED</prop> <prop key="change*">PROPAGATION_REQUIRED</prop> <prop key="get*">readOnly</prop> <prop key="*">readOnly</prop> </props> </property> </bean>
大家看下紅色代碼,這就是事務的配置, 在屬性key中,我定義了get*.意思是方法名只能是以get名稱開頭
而我卻寫成了Get 了,這樣就使用預設事務了<prop key="*">readOnly</prop>.所以報Connection is readonly. Queries leading to data modification are not allowed
呵呵,代碼規範命名
Spring事務報Connection is read-only