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>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • WCF分布式事务(EF)

    WCF分布式事务(EF)

  • 创建 Transact-SQL 作业步骤

    创建 Transact-SQL 作业步骤

  • 关于this指针

    关于this指针一个类的对象中实际只包含了该对象的数据成员信息,当我们创建了多个类的对象时,使对象1调用该类的成员函数,为什么可以改变对象1中的信息,而不去设置其他对象的信息?成员函数在类中只有一份,所有该类的对象共同使用,编译器是如何识别并处理的呢?编译器识别一个类分为三步:1.识别类的类名2.识别类的成员变量3.识别类的成员函数并对成员函数进行修改修改方式:成员函数有一个隐藏…

  • 腾讯面试题目汇总[通俗易懂]

    腾讯面试题目汇总面试官提问1:自我介绍及项目经历关于这道题,每个人的项目经历都不太一样,所以各位朋友根据自己的实际情况来介绍吧,在这里就不多介绍了。面试官提问2:看你项目介绍中大量使用了Redis,那能不能介绍下Redis的主从同步机制呢?关于这道题,因为我在之前的文章也分析过Redis主从同步的机制,所以我从完整重同步和部分重同步两个阶段去分析的,结果也得到了面试官的认可。详细的完整重同步和部分重同步机制原理是什么样的,在这里就不展开介绍了,附上链接朋友们自行查…

  • linux解压zip文件,

    linux解压zip文件,一,linux解压zip文件,命令:unzip如果没有该命令,可先安装,命令为:yum-yinstallunzip

  • Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)

    Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)

发表回复

您的电子邮箱地址不会被公开。

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