spring mybatis配置文件

<!-- 自动扫描bean,把作了注解的类转换为bean -->
<context:component-scan base-package="com.huawei.tbsc" annotation-config="true">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>

<!-- 读取资源文件 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties" />
</bean>

<!-- 配置数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">

<property name="driverClassName">
<value>${driver}</value>
</property>

<property name="url">
<value>${url}</value>
</property>

<property name="username">
<value>${username}</value>
</property>

<property name="password">
<value>${password}</value>
</property>

<!-- 数据库连接池最大连接数量 -->
<property name="maxActive">
<value>${maxActive}</value>
</property>

<!-- 数据库连接池最大空闲连接数量 --> 
<property name="maxIdle">
<value>${maxIdle}</value>
</property>
 
<!-- 数据库连接池最大等待连接数量 --> 
<property name="maxWait">
<value>${maxWait}</value>
</property>

</bean>

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis.xml" />
<property name="mapperLocations">
<list>
<value>classpath:com/huawei/tbsc/dao/impl/*-mapper.xml</value>
<value>classpath:com/huawei/tbsc/entity/*-resultMap.xml</value>
</list>
</property>
</bean>

<!-- 自动扫描Mapper接口,并实现其功能  -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.huawei.tbsc.dao" />
<property name="markerInterface" value="com.huawei.tbsc.dao.base.BaseMapper" />
</bean>

<!-- 事务配置 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

<tx:advice id="txAdvice" transaction-manager="transactionManager">

<tx:attributes>
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="page*" propagation="REQUIRED"  read-only="true"/>
<tx:method name="select*" propagation="REQUIRED"  read-only="true"/>
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
</tx:attributes>

</tx:advice>

<!-- 自动代理配置 -->
<aop:config>
<aop:pointcut expression="execution (* com.huawei.tbsc.service.impl.*.*(..))" id="service" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="service" />
</aop:config>

<!-- 标注类型 的事务配置 -->
<tx:annotation-driven transaction-manager="transactionManager" />

猜你喜欢

转载自mickey-hou.iteye.com/blog/1671831