Druid连接池与spring配置

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
<!-- 引入数据库信息的属性文件 -->
<context:property-placeholder location="classpath:conf/db_orcl.properties" />

<!-- 配置扫描器 -->
<context:component-scan base-package="com.hanqi.dao.mapper,com.hanqi.service.impl" />

<!-- 配置数据源 -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="driverClassName" value="${jdbc.driverClassName}"></property>
<property name="url" value="${jdbc.url}"></property>
</bean>

<!-- 配置Mybatis核心对象 SessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- mybatis中使用的别名 -->
<property name="typeAliasesPackage" value="com.hanqi.model"></property>
<!-- 注入数据源属性 -->
<property name="dataSource" ref="dataSource"></property>
<!-- Mybatis需要的映射文件 -->
<property name="mapperLocations" value="classpath:com/hanqi/dao/mapper/*Mapper.xml"></property>
</bean>

<!-- mybatis所有的映射接口 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.hanqi.dao"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>

<!-- spring提供的事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
<property name="enforceReadOnly" value="true"></property>
</bean>

<!-- 配置事务通知 -->
<tx:advice id="txadvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 事务的传播行为 -->
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="select*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>

<!-- springAOP的配置 -->
<aop:config proxy-target-class="true">
<!-- 以下标签的顺序不能改变 -->
<aop:pointcut expression="execution(* com.hanqi.dao.*.*(..))" id="aoppointcut"/>
<aop:advisor advice-ref="txadvice" pointcut-ref="aoppointcut" />
<aop:aspect ref="logginAspect">
<aop:before method="before" pointcut-ref="aoppointcut" />
<aop:after method="after" pointcut-ref="aoppointcut" />
<aop:after-throwing method="throwObject" throwing="exception" pointcut-ref="aoppointcut" />
<aop:after-returning method="returnObject" returning="object" pointcut-ref="aoppointcut" />
</aop:aspect>
</aop:config>

<!-- 开启spring声明式事务注解驱动 -->
<tx:annotation-driven transaction-manager="transactionManager" />

<!-- 配置切面类 -->
<bean id="logginAspect" class="util.LogginAspect"></bean>
</beans>

posted on 2017-11-29 22:23  superficial。  阅读(368)  评论(0编辑  收藏  举报

导航