`

spring声明式事务配置方法(六):aop:config切入

阅读更多
<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
    <bean id="testAction" class="test.action.Stuts2ActionTest">
        <property name="service" ref="templatesService"></property>
    </bean>

    <bean id="templatesService"
        class="test.service.impl.TaoTemplatesServiceImpl">
        <property name="dao" ref="templatesDAO" />
    </bean>

    <bean id="templatesDAO" class="test.dao.impl.TaoTemplatesDAOImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>


    <!--定义数据源-->
    <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource">
        <!--   定义数据库驱动-->
        <property name="driverClassName">
            <value>oracle.jdbc.driver.OracleDriver</value>
        </property>
        <!--   定义数据库url-->
        <property name="url">
            <value>jdbc:oracle:thin:@192.168.1.96:1521:yxdb</value>
        </property>
        <!--   定义数据库用户名-->
        <property name="username">
            <value>yxuser</value>
        </property>
        <!--   定义数据库密码-->
        <property name="password">
            <value>yxuser</value>
        </property>
    </bean>

    <!--定义一个hibernate的SessionFactory-->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <!--   定义SessionFactory必须注入DataSource-->
        <property name="dataSource">
            <ref local="dataSource" />
        </property>
        <property name="mappingResources">
            <list>
                <!--以下用来列出所有的PO映射文件-->
                <value>test/mapping/Tao_Templates.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.Oracle10gDialect
                </prop>
                <prop key="hibernate.show_sql">true</prop>
                <!--此处用来定义hibernate的SessionFactory的属性:
                    不同数据库连接,启动时选择create,update,create-drop -->
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
    </bean>

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

    <!-- 事务通知 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="add*" propagation="REQUIRED" />
            <tx:method name="del*" propagation="REQUIRED" />
            <tx:method name="mod*" propagation="REQUIRED" />
            <tx:method name="*" read-only="true" />
        </tx:attributes>
    </tx:advice>

    <!-- Spring AOP config -->
    <aop:config >
        <!-- 切入点 -->
        <aop:pointcut id="newServicesPointcut"
            expression="execution(* test.dao.impl.*.*(..))" />
        <aop:pointcut id="newServicesPointcut2"
            expression="execution(* com.yx.news.model.*.*(..))" />
        <aop:advisor advice-ref="txAdvice"
            pointcut-ref="newServicesPointcut" />
        <aop:advisor advice-ref="txAdvice"
            pointcut-ref="newServicesPointcut2" />
    </aop:config>

</beans>
 
分享到:
评论

相关推荐

    spring3,hibernate4 配置声明式事务管理(annotation方式)

    然后,启用Spring的AOP代理和声明式事务管理。在配置文件中加入以下内容: ```xml &lt;aop:config&gt; &lt;aop:pointcut id="serviceMethods" expression="execution(* com.example.service.*.*(..))"/&gt; &lt;aop:advisor ...

    Spring添加声明式事务.docx

    ### 一、Spring声明式事务的XML配置方式 在XML配置中,主要涉及以下三个步骤: 1. **配置事务管理器组件**:事务管理器是Spring中负责管理事务的核心组件。例如,`DataSourceTransactionManager`用于处理基于JDBC...

    ssh整合+spring声明式事务

    在SSH整合中,Spring的声明式事务管理是一个关键部分,它允许开发者无需在业务代码中显式控制事务的开始、提交和回滚,而是通过配置来决定哪些方法应该在事务中执行。 首先,让我们来看看SSH整合的步骤: 1. **...

    简单spring aop 例子

    Spring AOP(面向切面编程)是Spring框架的重要组成部分,它提供了一种模块化和声明式的方式来处理系统中的交叉关注点问题,如日志、事务管理、安全性等。本示例将简要介绍如何在Spring应用中实现AOP,通过实际的...

    spring事务与数据库操作

    ##### 1.2 配置Spring声明式事务 要启用Spring的声明式事务管理,通常需要做以下几步配置: - **配置数据源**:首先需要配置数据源,以便Spring能够访问数据库。 - **配置事务管理器**:接下来,需要配置一个事务...

    对Spring的AOP标签的支持

    总的来说,Spring的AOP标签使得开发者能够以声明式的方式实现切面,从而更方便地进行SSH项目的开发,无需侵入原有业务代码。通过合理利用这些标签,我们可以构建出更加模块化、易于维护的系统。

    spring 配置aop时需要的jar包

    2. 开启AOP代理:在Spring配置文件中,通过`&lt;aop:config&gt;`标签开启AOP支持,并可以定义切入点表达式(pointcut expression)和通知类型。 3. 定义切面:你可以使用Spring的`@Aspect`注解来定义一个切面类,然后在类...

    SpringAOP依赖包

    在Spring框架中,AOP通过代理模式实现,提供了声明式企业级服务,如事务管理、安全控制等,使得开发者无需在业务代码中插入这些繁琐的逻辑,从而提高了代码的可读性和可维护性。 首先,我们来了解Spring AOP的基本...

    SpringAOP的例子

    Spring AOP,全称Aspect-Oriented Programming(面向切面编程),是Spring框架的重要组成部分,它为Java应用程序提供了声明式的企业级服务,如事务管理、性能监控等。在这个"SpringAOP的例子"中,我们将深入探讨如何...

    Spring AOP源码笔记

    - **声明式事务控制**: 通过配置XML或使用`@Transactional`注解实现事务管理,无需在代码中显式管理事务。 - **事务属性**: 包括传播行为、隔离级别、回滚规则等,影响事务的执行方式。 **6. Spring事务原理** - **...

    Spring Aop的简单实现

    Spring AOP,全称Aspect-Oriented Programming(面向切面编程),是Spring框架的重要组成部分,它为应用程序提供了声明式的企业级服务,如日志、事务管理等。在本项目中,我们将探讨如何通过配置文件实现Spring AOP...

    spring事务管理

    Spring事务管理主要包括两种类型:编程式事务管理和声明式事务管理。 - **编程式事务管理**:通过编写代码来控制事务的开始、提交或回滚等操作。这种方式灵活度高,但会使得代码变得冗余且难以维护。 - **声明式...

    spring aop

    Spring AOP,全称为Aspect-Oriented Programming(面向切面编程),是Spring框架的重要组成部分,它为Java应用程序提供了声明式的企业级服务,如事务管理、日志记录等。AOP的核心概念是切面(Aspect)和通知(Advice...

    spring_aop1.rar_spring aop

    Spring AOP,全称为Aspect-Oriented Programming(面向切面编程),是Spring框架的重要组成部分,它为Java应用程序提供了声明式事务管理、日志记录、性能监控等许多实用功能。本资源"spring_aop1.rar"包含了一个经典...

    XML配置SpringAOP共2页.pdf.zip

    在处理事务时,Spring AOP经常被用来实现声明式事务管理。通过定义合适的切入点和通知,可以自动管理事务的开启、提交、回滚等操作,无需在业务代码中显式处理。 总结来说,XML配置Spring AOP涉及到创建切面、定义...

    spring AOP实例代码(带详细的讲解)

    Spring AOP,全称Aspect-Oriented Programming(面向切面编程),是Spring框架的重要组成部分,它为应用程序提供了声明式的企业级服务,如日志、事务管理等。在本实例代码中,我们将深入探讨Spring AOP的基本概念、...

    Spring_AOP笔记Spring_AOP笔记

    在Spring AOP中,配置切面主要是在`applicationContext.xml`配置文件中完成,或者使用注解式配置。例如,我们可以定义一个切面类,然后在其中声明通知方法,并使用`@Before`、`@After`等注解来标记这些方法。同时,...

    SpringAop实例

    它提供了一种模块化和声明式的方式来处理系统中的交叉关注点,如日志、事务管理、性能监控等,从而使得业务代码更加专注于核心功能。在Spring AOP中,这些关注点被封装为独立的模块,称为切面(Aspect)。 本实例...

    spring AOP 例子参考

    Spring AOP,全称为Aspect-Oriented Programming(面向切面编程),是Spring框架的重要组成部分,它为Java应用程序提供了声明式事务管理、日志记录、性能监控等跨切面关注点的解决方案。本教程将深入探讨Spring AOP...

    spring-nested-aop.zip_aop_spring aop

    它提供了一种模块化和声明式的方式来处理横切关注点,如事务管理、日志记录、性能监控等,这些关注点通常会分散在应用程序的各个角落。Spring AOP通过代理模式实现,允许我们在不修改源代码的情况下,对方法执行前后...

Global site tag (gtag.js) - Google Analytics