第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

我配置spring事務(wù)為什么不起作用

我配置spring事務(wù)為什么不起作用

開(kāi)心每一天1111 2019-03-03 04:00:34
application.xml 配置-------------------------------<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /></bean><bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"><property name="transactionManager" ref="txManager" /><property name="transactionAttributes"><props><prop key="save*">PROPAGATION_REQUIRED</prop><prop key="merge*">PROPAGATION_REQUIRED</prop><prop key="*">PROPAGATION_REQUIRED,readOnly</prop></props></property></bean>service 配置------------------<bean id="loginService" parent="txProxyTemplate"> <property name="target"> <bean class="com.play.login.service.impl.LoginServiceImpl"> <property name="loginDao" ref="loginDao" /></bean> </property> </bean>
查看完整描述

2 回答

?
達(dá)令說(shuō)

TA貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超6個(gè)贊

事務(wù)直接配到DAO
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

<bean id="baseTxProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
lazy-init="true" abstract="true">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="update*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

<bean id="studentDaoProxy" parent="baseTxProxy">
<property name="target">
<ref bean="studentDao" />
</property>
</bean>

<bean id="studentDao" class="com.dao.StudentDaoImpl">
<property name="dataSource" ref="dataSource" />
</bean>

StudentDao st = (StudentDao) context.getBean("studentDaoProxy");

兩個(gè)bean也可以合并為
<bean id="studentDao" parent="baseTxProxy">
<property name="target">
<bean class="com.dao.StudentDaoImpl">
<property name="dataSource" ref="dataSource" />
<property name="kpiDao" ref="kpiDao" />
</bean>
</property>
</bean>
StudentDao st = (StudentDao) context.getBean("studentDao");
上述這種方式必須使用接口,為什么。

第二種同樣必須用接口。配置起來(lái)比第一種麻煩
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="update*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="studentDaoProxy"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" ref="studentDao" />
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>

<bean id="studentDao" class="com.dao.StudentDaoImpl">
<property name="dataSource" ref="dataSource" />
</bean>
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
StudentDao st = (StudentDao) context.getBean("studentDaoProxy");

如果使用的都是接口,那么就不需要用cglib-nodep-2.1_3.jar
如果service調(diào)dao沒(méi)有用到接口,那么必須用cglib-nodep-2.1_3.jar


查看完整回答
反對(duì) 回復(fù) 2019-03-10
  • 2 回答
  • 0 關(guān)注
  • 1611 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)