mybatis整合spring配置文件
来源:互联网 发布:淘宝游戏币交易平台 编辑:程序博客网 时间:2024/05/17 06:31
<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
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/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
<!-- 引入配置文件 -->
<context:component-scan base-package="com.peter.service.*" />
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<!-- 初始化连接大小 -->
<property name="initialSize" value="${initialSize}"></property>
<!-- 连接池最大数量 -->
<property name="maxActive" value="${maxActive}"></property>
<!-- 连接池最大空闲 -->
<property name="maxIdle" value="${maxIdle}"></property>
<!-- 连接池最小空闲 -->
<property name="minIdle" value="${minIdle}"></property>
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="${maxWait}"></property>
</bean>
<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:com/peter/mapping/*.xml"></property>
</bean>
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.peter.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<aop:config>
<aop:pointcut id="serviceMethods" expression="execution(* *..service.*ServiceImpl.*(..))" />
<aop:advisor id="actionTx" advice-ref="txAdvice" pointcut-ref="serviceMethods" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="find*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="load*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="select*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="query*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="httpGet*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="httpFind*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="httpLoad*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="httpSelect*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="httpQuery*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Throwable" />
</tx:attributes>
</tx:advice>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
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/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
<!-- 引入配置文件 -->
<context:component-scan base-package="com.peter.service.*" />
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<!-- 初始化连接大小 -->
<property name="initialSize" value="${initialSize}"></property>
<!-- 连接池最大数量 -->
<property name="maxActive" value="${maxActive}"></property>
<!-- 连接池最大空闲 -->
<property name="maxIdle" value="${maxIdle}"></property>
<!-- 连接池最小空闲 -->
<property name="minIdle" value="${minIdle}"></property>
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="${maxWait}"></property>
</bean>
<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:com/peter/mapping/*.xml"></property>
</bean>
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.peter.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<aop:config>
<aop:pointcut id="serviceMethods" expression="execution(* *..service.*ServiceImpl.*(..))" />
<aop:advisor id="actionTx" advice-ref="txAdvice" pointcut-ref="serviceMethods" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="find*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="load*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="select*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="query*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="httpGet*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="httpFind*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="httpLoad*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="httpSelect*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="httpQuery*" propagation="SUPPORTS" isolation="DEFAULT" read-only="true" />
<tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Throwable" />
</tx:attributes>
</tx:advice>
</beans>
0 0
- spring-mybatis整合(配置文件)
- mybatis整合spring配置文件
- Spring与Mybatis整合配置文件
- struts2 + spring + mybatis 整合配置文件
- spring与mybatis整合配置文件
- mybatis与spring整合配置文件
- spring mybatis整合读取配置文件
- spring+springmvc+mybatis整合配置文件
- spring整合mybatis的配置文件
- Spring、Spring MVC、Mybatis整合配置文件详解
- mybatis与spring整合(基于配置文件)
- mybatis与spring整合(基于配置文件)
- mybatis与spring整合(基于配置文件)
- mybatis与spring整合(基于配置文件)
- mybatis与spring整合(基于配置文件)
- mybatis与spring整合(基于配置文件)
- mybatis与spring整合(基于配置文件)
- mybatis与spring整合(基于配置文件)
- 设计模式-访问者模式
- nyoj1058 部分和问题
- 文章标题
- Android Studio 删除module
- apache 服务器禁止http方法 解决appscan 使用 HTTP 动词篡改的认证旁路漏洞
- mybatis整合spring配置文件
- How to capture video frames from the camera as images using AV Foundation on iOS
- Android Studio Error:Execution failed for task ':xxxxx:mergeDebugResources'
- No command 'mmm' found
- HDU 2795 Billboard 线段树
- EasyUI 提示框
- Linux下redis的安装
- 文章
- 倒计时