|
|
<?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: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.1.xsd
|
|
|
http://www.springframework.org/schema/context
|
|
|
http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
|
|
|
<!-- 自动扫描 -->
|
|
|
<context:component-scan base-package="com.cya"/>
|
|
|
|
|
|
<!-- 引入配置文件 -->
|
|
|
<bean id="propertyConfigurer"
|
|
|
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
|
|
<property name="locations">
|
|
|
<value>classpath:dbconfig.properties</value>
|
|
|
</property>
|
|
|
</bean>
|
|
|
|
|
|
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
|
|
|
destroy-method="close">
|
|
|
<property name="url" value="${jdbc.url}" />
|
|
|
<property name="username" value="${jdbc.username}" />
|
|
|
<property name="password" value="${jdbc.password}" />
|
|
|
<property name="driverClassName" value="${jdbc.driver}" />
|
|
|
<property name="maxActive" value="10" />
|
|
|
<property name="minIdle" value="5" />
|
|
|
</bean>
|
|
|
|
|
|
|
|
|
<!-- spring和MyBatis整合 -->
|
|
|
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
|
|
|
<property name="dataSource" ref="dataSource"/>
|
|
|
<!--mybatis分页插件-->
|
|
|
<property name="configLocation" value="classpath:mybatis.xml"></property>
|
|
|
<!-- 自动扫描mapping.xml文件 -->
|
|
|
<property name="mapperLocations" value="classpath*:com.cya.mapper/*.xml"></property>
|
|
|
</bean>
|
|
|
|
|
|
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
|
|
|
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
|
|
|
<property name="basePackage" value="com.cya.mapper"/>
|
|
|
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
|
|
|
</bean>
|
|
|
|
|
|
<!-- 事务管理 -->
|
|
|
<bean id="transactionManager"
|
|
|
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
|
|
<property name="dataSource" ref="dataSource"/>
|
|
|
</bean>
|
|
|
|
|
|
<!--支持事务注解的(@Transactional)-->
|
|
|
<tx:annotation-driven transaction-manager="transactionManager"/>
|
|
|
|
|
|
</beans> |