`

Spring2.0事务(jdbc/hibernate)

阅读更多

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">


<bean id="conn" class="org.apache.commons.dbcp.BasicDataSource">
   <property name="driverClassName"
    value="com.microsoft.jdbc.sqlserver.SQLServerDriver">
   </property>
   <property name="url"
    value="jdbc:microsoft:sqlserver://localhost:1433">
   </property>
   <property name="username" value="sa"></property>
</bean>
<bean id="sess"
   class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
   <property name="dataSource">
    <ref bean="conn" />
   </property>
   <property name="hibernateProperties">
    <props>
     <prop key="hibernate.dialect">
      org.hibernate.dialect.SQLServerDialect
     </prop>
    </props>
   </property>
   <property name="mappingResources">
    <list>
     <value>po/Admin.hbm.xml</value>
    </list>
   </property>
</bean>

<bean id="hibernateTransactionManager"
   class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory">
    <ref bean="sess" />
   </property>
</bean>

<tx:advice transaction-manager="hibernateTransactionManager"
   id="txAdvice">
   <tx:attributes>
    <tx:method name="*" propagation="REQUIRED"></tx:method>
   </tx:attributes>
</tx:advice>

<aop:config>
   <aop:pointcut id="myPoint"
    expression="execution(* com.services..*.*(..))" />
   <aop:advisor advice-ref="txAdvice" pointcut-ref="myPoint" />
</aop:config>

<bean id="adminDAO" class="po.AdminDAO">
   <property name="sessionFactory">
    <ref bean="sess" />
   </property>
</bean>

<bean id="adminService" class="com.services.AdminServices">
   <property name="adminDAO">
    <ref bean="adminDAO" />
   </property>
</bean>
</beans>

===================================================================

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" />
<aop:aspectj-autoproxy/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
    <property name="url" value="jdbc:microsoft:sqlserver://localhost:1433"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>
</bean>


<bean name="adminDAO" class="com.test.AdminDAO"
   init-method="init">
   <property name="ds">
    <ref bean="dataSource" />
   </property>
</bean>

<bean name="check" class="com.services.Check">
   <property name="admindao">
    <ref bean="adminDAO" />
   </property>
</bean>

<bean id="txManager"
   class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
   <property name="dataSource" ref="dataSource" />
</bean>

<tx:advice id="txAdvice" transaction-manager="txManager">
   <tx:attributes>
    <tx:method name="get*" read-only="true" />
    <tx:method name="*" />
   </tx:attributes>
</tx:advice>

<aop:config>
   <aop:pointcut id="fooServiceOperation"
    expression="execution(* com.*services*.*(..))" />
   <aop:advisor advice-ref="txAdvice"
    pointcut-ref="fooServiceOperation" />
</aop:config>

</beans>

 

 

分享到:
评论

相关推荐

    spring2.0技术手册 (扫描版)

    第5章JDBC、事务支持 第6章Hibernate与Spring 第7章SpringWebMVC框架 第8章View层方案、Web框架整合 第9章API封装 第10章项目:Spring在线书签 Spring Framework 是一个开源的Java/Java EE全功能栈(full-stack)...

    Spring2.0宝典 源码

    全书分22章,内容涵盖了Spring的核心机制、依赖注入、资源访问、AOP框架、事务框架、整合Hibernate、DAO支持、JDBC支持、MVC框架、整合第三方表现层技术、整合第三方MVC框架、远程访问支持、EJB访问和实现、Spring对...

    SPRING2.0中文帮助文档

    在此基础上,Spring还提供了包括声明式事务管理,RMI或Web Services远程访问业务逻辑,以及可以多种方法进行的持久化数据库地解决方案。另外,Spring还有一个全功能的 MVC框架,并能透明的把 AOP 集成到你的软件中去...

    Spring 2.0 开发参考手册

    2. Spring 2.0 的新特性 2.1. 简介 2.2. 控制反转(IoC)容器 2.2.1. 更简单的XML配置 2.2.2. 新的bean作用域 2.2.3. 可扩展的XML编写 2.3. 面向切面编程(AOP) 2.3.1. 更加简单的AOP XML配置 2.3.2. 对@...

    spring 2.0中文API

    在此基础上,Spring还提供了包括声明式事务管理,RMI或Web Services远程访问业务逻辑,以及可以多种方法进行的持久化数据库地解决方案。另外,Spring还有一个全功能的 MVC框架,并能透明的把 AOP 集成到你的软件中去...

    spring2.0中文开发参考手册

    在此基础上,Spring还提供了包括声明式事务管理,RMI或Web Services远程访问业务逻辑,以及可以多种方法进行的持久化数据库地解决方案。另外,Spring还有一个全功能的 MVC框架,并能透明的把 AOP 集成到你的软件中去...

    spring2.0开发手册

    例如,你可以利用控制反转容器在前台的展现层使用Struts,还可以只使用 Hibernate集成编码 或是 JDBC抽象层 去处理数据存储。Spring被设计成(并将继续保持)无侵入性的方式,意味着应用几乎不需要对框架进行依赖...

    spring+struts+hibernate+dwr+jstl做的实例

    struts hibernate dwr 与Spring完全结合,实现用户列表、信息增、删、改、查、维护时用户重名提示等功能,还包括页面自动转码设置(web.xml),Hibernate管理服务按Bean名称拦截并进行Spring事务管理,完全由Spring...

    用户注册和登录是每个系统的必须存在的一部分,基于Dwr+Struts2+Spring+Hibernate写了一个用户登录注册系统

    事务处理也交由Spring去管理。  压缩文件中不包含Jar文件(由于全部的Jar将近12M,不能全部上传),所用到的Jar目录为,工程中再也不会出现由于MyEclipse自动整合而出现的大量Jar文件 : Java代码 1. //如果不用,...

    Spring 2.5 jar 所有开发包及完整文档及项目开发实例

    13) spring-mock.jar需spring-core.jar,spring-beans.jar,spring-dao.jar,spring-context.jar,spring-jdbc.jarspring2.0和spring2.5及以上版本的jar包区别Spring 2.5的Jar打包 在Spring 2.5中, Spring Web MVC...

    Spring in Action(第2版)中文版

    6.4.3在spring2.0里声明事务 6.4.4定义注释驱动事务 6.5小结 第7章保护spring 7.1springsecurity介绍 7.2验证用户身份 7.2.1配置providermanager 7.2.2根据数据库验证身份 7.2.3根据ldap仓库进行身份验证 ...

    Spring in Action(第二版 中文高清版).part2

    6.4.3 在Spring 2.0里声明事务 6.4.4 定义注释驱动事务 6.5 小结 第7章 保护Spring 7.1 Spring Security介绍 7.2 验证用户身份 7.2.1 配置Provider Manager 7.2.2 根据数据库验证身份 7.2.3 根据LDAP仓库...

    Spring in Action(第二版 中文高清版).part1

    6.4.3 在Spring 2.0里声明事务 6.4.4 定义注释驱动事务 6.5 小结 第7章 保护Spring 7.1 Spring Security介绍 7.2 验证用户身份 7.2.1 配置Provider Manager 7.2.2 根据数据库验证身份 7.2.3 根据LDAP仓库...

    Spring-Reference_zh_CN(Spring中文参考手册)

    2. Spring 2.0 的新特性 2.1. 简介 2.2. 控制反转(IoC)容器 2.2.1. 更简单的XML配置 2.2.2. 新的bean作用域 2.2.3. 可扩展的XML编写 2.3. 面向切面编程(AOP) 2.3.1. 更加简单的AOP XML配置 2.3.2. 对@AspectJ 切面的...

    spring chm文档

    2. Spring 2.0 的新特性 2.1. 简介 2.2. 控制反转(IoC)容器 2.2.1. 更简单的XML配置 2.2.2. 新的bean作用域 2.2.3. 可扩展的XML编写 2.3. 面向切面编程(AOP) 2.3.1. 更加简单的AOP XML配置 2.3.2. 对@...

    Spring API

    2. Spring 2.0和 2.5的新特性 2.1. 简介 2.2. 控制反转(IoC)容器 2.2.1. 新的bean作用域 2.2.2. 更简单的XML配置 2.2.3. 可扩展的XML编写 2.2.4. Annotation(注解)驱动配置 2.2.5. 在classpath中自动搜索组件...

    Java求职面试宝典各大公司常考知识点

    Struts+Hibernate+Spring面试题合集及答案 Struts+Hibernate+Spring面试题合集 1 1. Hibernate部分 2 ...4.2. Hibernate与jdbc的联系 22 4.3. Hibernate与spring的联系 22 4.4. 项目中为什么使用SSH 23

    Spring中文帮助文档

    9.5.1. 理解Spring的声明式事务管理实现 9.5.2. 第一个例子 9.5.3. 回滚 9.5.4. 为不同的bean配置不同的事务语义 9.5.5. &lt;tx:advice/&gt; 有关的设置 9.5.6. 使用 @Transactional 9.5.7. 事务传播 9.5.8. 通知...

    《MyEclipse 6 Java 开发中文教程》前10章

    10.5.2.5 用Spring 2.0 的@Transactional标注解决事务提交问题(最佳方案) 251 10.5.2.6 使用 HibernateTemplate 实现分页查询 254 10.6 小结 255 10.7 参考资料 255 10.7.1 MyEclipse生成的Spring+Hibernate无法...

Global site tag (gtag.js) - Google Analytics