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 -->

 

你可能感兴趣的:(DAO,spring,AOP,Hibernate,bean)