前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >applicationContext.xml详解

applicationContext.xml详解

作者头像
全栈程序员站长
发布2022-09-14 11:22:53
3490
发布2022-09-14 11:22:53
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

applicationContext.xml

代码语言:javascript
复制
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">

    <!--1.配置包扫描  -->
    <context:component-scan base-package="com.jt"/>

    <!--2.配置数据源  -->

    <!--2.1导入pro配置文件  -->
    <context:property-placeholder location="classpath:/property/jdbc.properties" />

    <!--2.2配置数据源  -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>


    <!--3.配置事务控制  -->
    <tx:annotation-driven/>

    <!--3.1 定义事务管理器  -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!--3.2 定义事务策略

        propagation="REQUIRED" 执行该操作 必须添加事务
        propagation="SUPPORTS" 事务支持的,原来的操作有事务,则添加事务,
                                    原有的操作没有事务,则不添加事务

        propagation="NEVER"    从不添加事务
        propagation="REQUIRES_NEW"   都会创建一个新的事务
        read-only="true"       该操作只读
      -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="save*"   propagation="REQUIRED"/>
            <tx:method name="delete*" propagation="REQUIRED"/>
            <tx:method name="update*" propagation="REQUIRED"/>
            <tx:method name="find*"   propagation="SUPPORTS" read-only="true"/>
            <tx:method name="*"       propagation="SUPPORTS" read-only="true"/>
        </tx:attributes>
    </tx:advice>

    <!--3.3 定义事务切面
        (pointcut*, advisor*, aspect*)

        expression 切入点表达式
        within(包名.类名)  按类匹配  控制粒度 粗粒度
        execution(返回值类型 包名.类名.方法名(参数列表))
    -->
    <aop:config>
        <aop:pointcut expression="execution(* com.jt.manage.service..*.*(..))" id="pc"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="pc"/>
    </aop:config>
</beans>

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/158358.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年7月1,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • applicationContext.xml
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档