对spring整合不是很熟悉。请问以下的配置是否包含了事务。是这个吗?baseTransactionProxy。
如果我把这段配置用于实际项目中。会不会有什么问题,请指教!谢谢
[code="java"]
<!--
以下是 ibatis的配置 -->
<bean id="propertyConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:jdbc.properties</value>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!--根据dataSource和configLocation创建一个SqlMapClient-->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:SqlMapConfig.xml</value>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<!--根据sqlMapClien创建一个SqlMapClient模版类-->
<!-- spring 的事务处理类配置 -->
<!-- spring 的事务处理代理配置 -->
<bean id="baseTransactionProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
lazy-init="true" abstract="true">
<!-- 它有个属性叫“事务处理”,下面会声明的 -->
<property name="transactionManager">
<ref bean="transactionManagerIbatis" />
</property>
<!--这里就声明了具体的事务 -->
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
<prop key="modify*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
[/code]
[b]问题补充:[/b]
我的spring是这样配置的:
[code="java"]
[/code]
这样也没有问题吧?
To lovewhzlq
我还没有达到你说的境界。哪有有文章说明这个。我想看看。
我从来没有在软件公司做过。在企业里,而且是单打独斗。水平很差,只能是不停地学习。hibernate会一些,所以还想学习ibatis和JPA。唉,什么时候达到你那水平,
to huangnetian ,谢谢你的热心,有问题我一定会问的。!!
这样吧,我把我项目中的东西拿来发给你一份,你自己去慢慢琢磨吧,有不明白的就提.
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
value="${query.jdbc.driverClassName}" />
<!--配置ibatis的资源文件载入-->
<bean id="querySqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:conf/sqlMap-config.xml</value>
</property>
<property name="dataSource">
<ref local="queryDataSource" />
</property>
</bean>
<bean id="updateDataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName"
value="${update.jdbc.driverClassName}" />
<property name="url" value="${update.jdbc.url}" />
<property name="username" value="${update.jdbc.username}" />
<property name="password" value="${update.jdbc.password}" />
<property name="maxActive" value="100" />
<property name="maxIdle" value="10" />
<property name="maxWait" value="10000" />
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="60" />
<property name="logAbandoned" value="true" />
</bean>
<!--配置ibatis的资源文件载入-->
<bean id="updateSqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>classpath:conf/sqlMap-config.xml</value>
</property>
<property name="dataSource">
<ref local="updateDataSource" />
</property>
</bean>
<bean id="sqlMapDaoTemplate"
class="com.incesoft.guess.dao.base.DefaultSqlMapDaoTemplate">
<property name="querySqlMapClientTemplate">
<bean
class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient" ref="querySqlMapClient"></property>
</bean>
</property>
<property name="updateSqlMapClientTemplate">
<bean
class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient"
ref="updateSqlMapClient">
</property>
</bean>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref bean="updateDataSource" />
</property>
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref local="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
<bean name="beanNameAutoProxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator" />
<bean id="transactionProxy" parent="beanNameAutoProxy">
<property name="beanNames">
<list>
<value>accountManager</value>
<value>guessManager</value>
</list>
</property>
<property name="interceptorNames">
<value>transactionInterceptor</value>
</property>
</bean>
可能出现的问题是抛出异常后不能回滚
这里说得很明白,spring和ibatis的整合
[url]http://www.iteye.com/topic/323378[/url]
基本配置是没什么问题啦,
还是要针对实际项目的需求再看具体需要的更细节的配置
没什么问题的,如果你在用的过程中遇到问题,再把问题贴出来,我帮你解决.你的配置正确.但根据你的配置只有insert,save等方法开头的service才具有回滚能力,别忘了
只能是不停地学习,你有这种想法就很够了,
学习也是靠不断的实践出经验的,其实很多东西自己多试试,也许就试出经验,发现更多的经验了,
祝你学习进步飞速哈,加油!
朋友,问题要自动关闭啦,结分哦