Spring +hibernate 声明式 事物 + annotation

在applicationContext.xml中

 

<!-- 事务配置 -->
	<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
	</bean>
	
	<!-- 支持 @Transactional 标记 -->
	<tx:annotation-driven proxy-target-class="true" transaction-manager="txManager"/>
	
	<!-- 使用annotation定义事务 -->
	<tx:annotation-driven transaction-manager="txManager" />
 
	<!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 -->
	<context:annotation-config/> 
	<context:component-scan base-package="com.club" />

 

 

在manager层(service层)中,给impl类或者impl类下的方法上加

@Service
@Transactional(propagation=Propagation.REQUIRED)
 

 

你可能感兴趣的:(annotation)