
conf.spring-mybatis.xml Maven / Gradle / Ivy
<?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: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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"> <!-- 数据库连接配置 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <property name="driverClassName" value="${jdbc_driverClassName}" /> <property name="url" value="${jdbc_url}" /> <property name="username" value="${jdbc_username}" /> <property name="password" value="${jdbc_password}" /> <!-- 连接池最大使用连接数 spring-mybatis --> <property name="maxActive" value="${max_url}" /> <!-- 初始化连接大小 --> <property name="initialSize" value="${d_Szie}" /> <!-- 获取连接最大等待时间 --> <property name="maxWait" value="${max_Wait}" /> <!-- 连接池最大空闲 --> <property name="maxIdle" value="${max_Idle}" /> <!-- 连接池最小空闲 --> <property name="minIdle" value="${max_Idle}" /> <!-- 自动清除无用连接 --> <property name="removeAbandoned" value="${removeAbandoned}" /> <!-- 清除无用连接的等待时间 --> <property name="removeAbandonedTimeout" value="${removeAbandonedTimeout}" /> <!-- 连接属性 --> <property name="connectionProperties" value="clientEncoding=UTF-8" /> <!-- 配置监控统计拦截的filters 去掉后监控界面sql无法统计开启web监控、开启sql防火墙 --> <property name="filters" value="stat,wall"></property> </bean> <!-- mybatis文件配置,扫描所有mapper文件 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" p:dataSource-ref="dataSource" p:configLocation="classpath:conf/mybatis-config-page.xml" p:mapperLocations="classpath:cn/springmvc/dao/*/*.xml"/> <!-- p:configLocation="classpath:conf/mybatis-config.xml" --> <!-- configLocation为mybatis属性 mapperLocations为所有mapper--> <!-- spring与mybatis整合配置,扫描所有dao --> <!-- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" p:basePackage="cn.basics.dao" p:sqlSessionFactoryBeanName="sqlSessionFactory"/> --> <!-- 对数据源进行事务管理 ↓--> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource" /> <!-- 业务逻辑事务处理 ↓--> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="delete*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/> <tx:method name="insert*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" /> <tx:method name="update*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" /> <tx:method name="save*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" /> <tx:method name="add*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" /> <tx:method name="get*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" /> <tx:method name="select*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" /> <tx:method name="find*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" /> </tx:attributes> </tx:advice> <aop:aspectj-autoproxy proxy-target-class="true"/> <!-- 事物处理 --> <aop:config> <aop:pointcut id="pc" expression="execution(* cn.basics.service..*.*(..))" /> <aop:advisor pointcut-ref="pc" advice-ref="txAdvice" /> </aop:config> <!-- 业务逻辑事务处理 ↑--> </beans>
© 2015 - 2025 Weber Informatics LLC | Privacy Policy