美术馆网站的建设流程,境外服务器租用,企业所得税25%怎么计算,查域名ipSpring配置文件中关于事务配置总是由三个组成部分#xff0c;分别是DataSource、TransactionManager和代理机制这三部分#xff0c;无论哪种配置方式#xff0c;一般变化的只是代理机制这部分。 DataSource、TransactionManager这两部分只是会根据数据访问方式有所变化… Spring配置文件中关于事务配置总是由三个组成部分分别是DataSource、TransactionManager和代理机制这三部分无论哪种配置方式一般变化的只是代理机制这部分。 DataSource、TransactionManager这两部分只是会根据数据访问方式有所变化比如使用Hibernate进行数据访问时DataSource实际为SessionFactoryTransactionManager的实现为HibernateTransactionManager。 具体如下图 根据代理机制的不同总结了五种Spring事务的配置方式配置文件如下 第一种方式每个Bean都有一个代理 ?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsdbean idsessionFactory classorg.springframework.orm.hibernate3.LocalSessionFactoryBean property nameconfigLocation valueclasspath:hibernate.cfg.xml / property nameconfigurationClass valueorg.hibernate.cfg.AnnotationConfiguration //bean !-- 定义事务管理器声明式的事务 -- bean idtransactionManagerclassorg.springframework.orm.hibernate3.HibernateTransactionManagerproperty namesessionFactory refsessionFactory //bean!-- 配置DAO --bean iduserDaoTarget classcom.bluesky.spring.dao.UserDaoImplproperty namesessionFactory refsessionFactory //beanbean iduserDao classorg.springframework.transaction.interceptor.TransactionProxyFactoryBean !-- 配置事务管理器 -- property nametransactionManager reftransactionManager / property nametarget refuserDaoTarget / property nameproxyInterfaces valuecom.bluesky.spring.dao.GeneratorDao /!-- 配置事务属性 -- property nametransactionAttributes props prop key*PROPAGATION_REQUIRED/prop/props /property /bean
/beans 第二种方式所有Bean共享一个代理基类 ?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsdbean idsessionFactory classorg.springframework.orm.hibernate3.LocalSessionFactoryBean property nameconfigLocation valueclasspath:hibernate.cfg.xml / property nameconfigurationClass valueorg.hibernate.cfg.AnnotationConfiguration //bean !-- 定义事务管理器声明式的事务 -- bean idtransactionManagerclassorg.springframework.orm.hibernate3.HibernateTransactionManagerproperty namesessionFactory refsessionFactory //beanbean idtransactionBase classorg.springframework.transaction.interceptor.TransactionProxyFactoryBean lazy-inittrue abstracttrue !-- 配置事务管理器 -- property nametransactionManager reftransactionManager / !-- 配置事务属性 -- property nametransactionAttributes props prop key*PROPAGATION_REQUIRED/prop /props /property /bean !-- 配置DAO --bean iduserDaoTarget classcom.bluesky.spring.dao.UserDaoImplproperty namesessionFactory refsessionFactory //beanbean iduserDao parenttransactionBase property nametarget refuserDaoTarget / /bean
/beans 第三种方式使用拦截器 ?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsdbean idsessionFactory classorg.springframework.orm.hibernate3.LocalSessionFactoryBean property nameconfigLocation valueclasspath:hibernate.cfg.xml / property nameconfigurationClass valueorg.hibernate.cfg.AnnotationConfiguration //bean !-- 定义事务管理器声明式的事务 -- bean idtransactionManagerclassorg.springframework.orm.hibernate3.HibernateTransactionManagerproperty namesessionFactory refsessionFactory //bean bean idtransactionInterceptor classorg.springframework.transaction.interceptor.TransactionInterceptor property nametransactionManager reftransactionManager / !-- 配置事务属性 -- property nametransactionAttributes props prop key*PROPAGATION_REQUIRED/prop /props /property /beanbean classorg.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator property namebeanNames list value*Dao/value/list /property property nameinterceptorNames list valuetransactionInterceptor/value /list /property /bean !-- 配置DAO --bean iduserDao classcom.bluesky.spring.dao.UserDaoImplproperty namesessionFactory refsessionFactory //bean
/beans 第四种方式使用tx标签配置的拦截器 ?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxmlns:txhttp://www.springframework.org/schema/txxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsdcontext:annotation-config /context:component-scan base-packagecom.bluesky /bean idsessionFactory classorg.springframework.orm.hibernate3.LocalSessionFactoryBean property nameconfigLocation valueclasspath:hibernate.cfg.xml / property nameconfigurationClass valueorg.hibernate.cfg.AnnotationConfiguration //bean !-- 定义事务管理器声明式的事务 -- bean idtransactionManagerclassorg.springframework.orm.hibernate3.HibernateTransactionManagerproperty namesessionFactory refsessionFactory //beantx:advice idtxAdvice transaction-managertransactionManagertx:attributestx:method name* propagationREQUIRED //tx:attributes/tx:adviceaop:configaop:pointcut idinterceptorPointCutsexpressionexecution(* com.bluesky.spring.dao.*.*(..)) /aop:advisor advice-reftxAdvicepointcut-refinterceptorPointCuts / /aop:config
/beans 第五种方式全注解 ?xml version1.0 encodingUTF-8?
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxmlns:txhttp://www.springframework.org/schema/txxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsdcontext:annotation-config /context:component-scan base-packagecom.bluesky /tx:annotation-driven transaction-managertransactionManager/bean idsessionFactory classorg.springframework.orm.hibernate3.LocalSessionFactoryBean property nameconfigLocation valueclasspath:hibernate.cfg.xml / property nameconfigurationClass valueorg.hibernate.cfg.AnnotationConfiguration //bean !-- 定义事务管理器声明式的事务 -- bean idtransactionManagerclassorg.springframework.orm.hibernate3.HibernateTransactionManagerproperty namesessionFactory refsessionFactory //bean/beans 此时在DAO上需加上Transactional注解如下 package com.bluesky.spring.dao;import java.util.List;import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;import com.bluesky.spring.domain.User;Transactional
Component(userDao)
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {public ListUser listUsers() {return this.getSession().createQuery(from User).list();}} 转载于:https://www.cnblogs.com/gy19920604/p/5288613.html