`
IThead
  • 浏览: 419784 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

SSH事务配置全集

阅读更多
配置声明式事务的方法如下:
<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<property name="transactionManager" ref="transactionManager"/>
		<property name="transactionAttributes">
			<props>
				<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="list*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="add*">PROPAGATION_REQUIRED</prop>
				<prop key="create*">PROPAGATION_REQUIRED</prop>
				<prop key="update*">PROPAGATION_REQUIRED</prop>
				<prop key="delete*">PROPAGATION_REQUIRED</prop>
				<prop key="save*">PROPAGATION_REQUIRED</prop>
				<prop key="regedit*">PROPAGATION_REQUIRED</prop> 
				<prop key="remove*">PROPAGATION_REQUIRED</prop>
				<prop key="do*">PROPAGATION_REQUIRED</prop>
			</props>
		</property>
	</bean>
	
	<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="interceptorNames">
			<list>
				<value>baseTransactionProxy</value>
			</list>
		</property>
		<property name="beanNames">
			<list>
				<value>*Service</value>
			</list>
		</property>
	</bean>

完整的applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
	<bean id="helloService" class="com.tarena.service.HelloService">
		<property name="str" value="hello"></property>
	</bean>
	<bean id="dataSource"
		class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName"
			value="com.mysql.jdbc.Driver">
		</property>
		<property name="url" value="jdbc:mysql://localhost:3306/cle">
		</property>
		<property name="username" value="root"></property>
		<property name="password" value="root1234"></property>
	</bean>

	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="configLocation"
			value="classpath:hibernate.cfg.xml">
		</property>
		<property name="dataSource" ref="dataSource"></property>
		<!-- 
		<property name="mappingResources">
			<list>
				<value>com\tarena\entity\User.hbm.xml</value>
			</list>
		</property>
		 -->
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.MySQLDialect
				</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.hbm2ddl.auto">none</prop>
			</props>
		</property>
	</bean>

	<bean id="hibernateTemplate"
		class="org.springframework.orm.hibernate3.HibernateTemplate">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>

	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<property name="transactionManager" ref="transactionManager"/>
		<property name="transactionAttributes">
			<props>
				<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="list*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="add*">PROPAGATION_REQUIRED</prop>
				<prop key="create*">PROPAGATION_REQUIRED</prop>
				<prop key="update*">PROPAGATION_REQUIRED</prop>
				<prop key="delete*">PROPAGATION_REQUIRED</prop>
				<prop key="save*">PROPAGATION_REQUIRED</prop>
				<prop key="regedit*">PROPAGATION_REQUIRED</prop> 
				<prop key="remove*">PROPAGATION_REQUIRED</prop>
				<prop key="do*">PROPAGATION_REQUIRED</prop>
			</props>
		</property>
	</bean>
	
	<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="interceptorNames">
			<list>
				<value>baseTransactionProxy</value>
			</list>
		</property>
		<property name="beanNames">
			<list>
				<value>*Service</value>
			</list>
		</property>
	</bean>
	<bean id="userDao" class="com.tarena.dao.UserDaoImpl">
		<property name="hibernateTemplate" ref="hibernateTemplate"></property>
	</bean>
	
	<bean id="userService" class="com.tarena.service.UserServiceImpl">
		<property name="userDao" ref="userDao"></property>
	</bean>

	<bean id="loginAction" class="com.tarena.action.LoginAction">
		<property name="userService" ref="userService"></property>
	</bean>

</beans>
分享到:
评论
2 楼 IThead 2012-06-29  
lgs0626 写道
对这种毫无注释的东西!如何能看得懂!不想说

其实,主要是想给自己做个备份,也是刚开始学习这个,只是自己测试通过,但是对于注解的理解还不算很清楚。如果你对applicationContext.xml有深的理解可以提供一下,谢谢!
1 楼 lgs0626 2012-06-29  
对这种毫无注释的东西!如何能看得懂!不想说

相关推荐

Global site tag (gtag.js) - Google Analytics