Spring+Hibernate事务控制放在Service层处理

	<!-- DataSource,SessionFactory start-->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
		<property name="url" value="jdbc:hsqldb:hsql://localhost/" />
		<property name="username" value="SA" />
		<property name="password" value="" />
	</bean>
	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="mappingResources">
			<list>
				<value>/report/model/hibernate/po/User.hbm.xml</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<value>
				hibernate.dialect=org.hibernate.dialect.HSQLDialect
				hibernate.show_sql=true
            </value>
		</property>
	</bean>
	<!-- DataSource,SessionFactory end -->

	<!-- Transaction config start  -->
	<bean id="txManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>
	<bean abstract="true" id="serviceTxProxy"
		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
		<property name="transactionManager" ref="txManager"></property>
		<property name="transactionAttributes">
			<props>
				<prop key="add*">PROPAGATION_REQUIRED</prop>
				<prop key="del*">PROPAGATION_REQUIRED</prop>
				<prop key="mod*">PROPAGATION_REQUIRED</prop>
				<prop key="*">PROPAGATION_SUPPORTS, readOnly</prop>
			</props>
		</property>
	</bean>

	<!-- Transaction config end -->

	<!-- Authorization Management (AOP) -->

	<!-- Action Beans Start -->
	<bean id="userAction" class="report.action.UserAction">
		<property name="userService" ref="userService"></property>
	</bean>
	<!-- Action Beans End -->

	<!--  Service Proxy Start	-->
	<bean id="userService" parent="serviceTxProxy">
		<property name="target" ref="userServiceImpl"></property>
	</bean>
	<!--  Service Proxy End -->

	<!-- Service Impl Target Beans Start -->

	<bean id="userServiceImpl" class="report.service.hibernateImpl.UserServiceImpl">
		<property name="userDao" ref="userDao" />
		<property name="testDao" ref="testDao" />
	</bean>

	<!-- Service Impl Target Beans End -->

	<!-- Dao Proxy Start	-->
	<bean id="userDao" class="org.springframework.aop.framework.ProxyFactoryBean">
		<property name="proxyInterfaces"
			value="report.model.hibernate.dao.interfaces.UserDao" />
		<property name="interceptorNames">
			<list>
				<value>userDaoImpl</value>
			</list>
		</property>
	</bean>
	<bean id="testDao" class="org.springframework.aop.framework.ProxyFactoryBean">
		<property name="proxyInterfaces"
			value="report.model.hibernate.dao.interfaces.TestDao" />
		<property name="interceptorNames">
			<list>
				<value>testDaoImpl</value>
			</list>
		</property>
	</bean>

	<!-- Dao Proxy End -->

	<!-- Dao Impl Target Beans  Start -->
	<bean id="userDaoImpl" class="report.model.hibernate.dao.impl.UserDaoImpl">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	<bean id="testDaoImpl" class="report.model.hibernate.dao.impl.TestDaoImpl">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	<!-- Dao IMpl Target Beans  End -->

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值