笔记(杂项,自己看)
来源:互联网 发布:python scoket测试 编辑:程序博客网 时间:2024/06/06 04:56
Spring 引入属性文件的配置片段
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:config/database.properties</value> </list> </property></bean>
MyBatis 集成 Spring 的时候 ,让 MyBatis 去扫描接口(声明为 interface 的文件)和 xml 文件,我们应该这样写:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 注意:这里配置扫描所有的 mapper 文件 --> <property name="mapperLocations" value="classpath*:com/liwei/mybatis/model/*.xml"></property> --></bean>
配置扫描所有的接口(声明为 interface )文件:
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.liwei.mybatis.inter"></property></bean>
MyBatis 引入属性文件的配置:
Spring 声明式事务的配置参考:
第 1 种方式:使用 xml 配置的方式实现声明式事务管理
<!-- 第 1 步:要想使用事务,首先要实例化一个事务管理器 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property></bean><!-- 第 2 步:配置事务通知,这里配置的是最最简单的事务配置通知,不带事务传播特性,即所有的方法都开启了事务 --><tx:advice id="advice" transaction-manager="transactionManager"> <!-- 配置事务属性 --> <tx:attributes> <tx:method name="*"/> </tx:attributes></tx:advice><!-- 第 3 步:配置事务切面 --><aop:config> <!-- 配置切点 --> <aop:pointcut expression="execution(* com.liwei.tx.service.*.*(..))" id="serviceMethod"/> <aop:advisor advice-ref="advice" pointcut-ref="serviceMethod"/></aop:config>
参考资料:http://www.tuicool.com/articles/qEvy2m
第 2 种方式:使用 annotation 的方式实现声明式事务管理
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property></bean><tx:annotation-driven transaction-manager="transactionManager"/>
然后在须要定义事务的方法上写上注解:@Transactional
。
0 0
- 笔记(杂项,自己看)
- 笔记杂项
- 杂项笔记
- 杂项笔记
- c#学习笔记杂项(一)
- [文件系统]文件系统学习笔记(十)---杂项
- python学习笔记(四)--杂项
- MyBatis学习笔记(五)--MyBatis杂项
- JAVA的基础知识(给自己看的笔记)。
- 《写给大忙人看的java SE8》笔记 -- 3. 杂项改进与java7新特性
- linux 笔记 - 杂项
- Latex杂项笔记
- Qt杂项笔记
- Qt杂项笔记
- C#笔记 使用杂项
- 汇编学习笔记杂项
- Qt杂项笔记
- *计算机学习笔记杂项
- MATLAB 练习07 数值运算
- hdu5310 Souvenir(模拟)
- 堆串的应用
- Java Socket应用(七)——使用多线程实现多客户端的通信
- RelativeSource.TemplatedParent 属性wpf
- 笔记(杂项,自己看)
- HTTP学习要点(一)
- 为什么写博客
- Java依赖管理工具:Gradle
- BestCoder 1st Anniversary ($) Hidden String(深搜)
- 自定义ActionBar的风格
- strcpy
- 链串的基本运算
- 互联网秒杀设计