Spring 耦合dao service action

<bean id="sessionFactory"	class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="configLocation"
			value="classpath:hibernate.cfg.xml">
		</property>
	</bean>
	<!-- 配置daoBean -->
	<bean id="JdjLxfsDAO" class="com.jdj.dao.impl.JdjLxfsDAOImpl">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>
<bean  id="XtwhYhwhAction" class="com.jdj.action.XtwhYhwhAction" scope="prototype">
		<property name="xtwhYhwhDAO" ref="XtwhYhwhDAO"></property>
	</bean><!-- 定义事务管理器(声明式的事务) -->
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	<!-- 事务通知 -->
	<tx:advice id="txAdvice">
		<tx:attributes>
			<!-- 所有以get开头的方法都使用只读事务,使用只读连接,提高性能 -->
			<tx:method name="get*" read-only="true"  />
			<tx:method name="find*" read-only="true" />
			<tx:method name="findOnline" />
			<!-- 其它方法使用缺省事务 -->
			<tx:method name="*" />
		</tx:attributes>
	</tx:advice>
	<!-- 上述事务通知可以运行在com.demo.service包下所有的接口的所有方法上-->
	<aop:config>
		<!-- 定义切入点表达式-->
		<aop:pointcut id="defaultServiceOperation" expression="execution(* com.jdj.dao.*.*(..))" />
		<!-- 事务通知和切入点表达式进行关联-->
		<aop:advisor pointcut-ref="defaultServiceOperation"
			advice-ref="txAdvice" />
	</aop:config>


下面给出一些通用切入点表达式的例子。
任意公共方法的执行:
execution(public * *(..))
任何一个名字以“set”开始的方法的执行:
execution(* set*(..))
AccountService接口定义的任意方法的执行:
execution(* com.xyz.service.AccountService.*(..))
在service包中定义的任意方法的执行:
execution(* com.xyz.service.*.*(..))
在service包或其子包中定义的任意方法的执行:
execution(* com.xyz.service..*.*(..))

猜你喜欢

转载自everlxq.iteye.com/blog/1908264