applicationContext.xml详解

applicationContext.xml详解applicationContext.xml<beansxmlns=”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.springframewo

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

applicationContext.xml

<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.net/158358.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • laravel 分页样式「建议收藏」

    laravel 分页样式「建议收藏」第一种//控制器$news=News::where(‘type_id’,1)->where(‘is_del’,1)->paginate(3);//前端@if($news->currentPage()==1)@else<li><ahref=”{{url(‘news?page=1’)}}”>首页</a></li><li><ahref=”{{$news->previousPag

    2022年7月17日
    15
  • Gradle下载慢解决方案

    Gradle下载慢解决方案参考:阿里云公共代理库首先我们来看看google官方的依赖方式:buildscript{repositories{mavenCentral()jcenter()google()}dependencies{classpath’com.android.tools.build:gradle:3.0.1′}}allprojects{repositories{

    2022年6月15日
    27
  • Idea正则表达式一键替换注释,生成@ApiModelProperty(““)「建议收藏」

    平常日常开发中,返回给前端的vo对象在字段上需要加注释@ApiModelProperty(“xxx”),方便在前端同事在swagger文档看注释,一般我是domain对象生成之后,复制代码到vo对象里,然后再修改Java块注释为前端的注释@ApiModelProperty(“xxx”),那怎么从以下的代码注释转为@ApiModelProperty(“xxx”)注释呢?如果字段很多的话,一个一个写会比较耗时也枯燥,可以用正则表达式一键替。/***xxx*/(1)doma

    2022年4月14日
    160
  • Win32 API 访问路由的加密网页

    Win32 API 访问路由的加密网页

    2021年8月6日
    64
  • Java中的Scanner(详解常见用法)

    Java中的Scanner(详解常见用法)OJ中遇到的问题和例子:doublenextDouble(),floatnextFloat(),intnextInt()等与nextLine()连用时都存在遗留的换行符影响nextLine()读取输入的问题,解决的办法是:在每一个next()、nextDouble()、nextFloat()、nextInt()等语句之后加一个nextLine()语句,将被next()去掉的…

    2022年7月8日
    21
  • vim复制粘贴_vim剪切命令

    vim复制粘贴_vim剪切命令在Windows下我们习惯的操作,复制单个字符,复制单行多行,删除单行多行,在linux的vim中操作如下:G(shift+g+g):跳到文档尾g+g:跳转到文档首home键:光标移动到行首end键:光标移动到行尾yy:复制光标所在行的整行内容yw:复制光标所在单词的内容nyy:复制从光标开始向下的n行内容,n为复制的行数nyw:复制从光标所在字开始后的n个字,n为复制的字数p:粘贴,将复制的内容粘贴在光标所在的位置x(小x):删除光标所在位置的字符,同键盘上的del

    2022年9月22日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号