@
li24361 不好意思,我以为放出来了。
上面那个 applicationContext 给错了。
连接配置我是放在 applicationContext 的
<?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:util="
http://www.springframework.org/schema/util"
xmlns:context="
http://www.springframework.org/schema/context"
xmlns:jdbc="
http://www.springframework.org/schema/jdbc" xmlns:jee="
http://www.springframework.org/schema/jee"
xmlns:tx="
http://www.springframework.org/schema/tx" xmlns:task="
http://www.springframework.org/schema/task"
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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-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/util http://www.springframework.org/schema/util/spring-util-4.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd">
<description>Spring 公共配置</description>
<!-- 开启定时任务 -->
<task:annotation-driven />
<!-- MyBatis 配置 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 显式指定 Mapper 文件位置 -->
<property name="mapperLocations" value="classpath*:/mybatis/*Mapper.xml" />
<!-- mybatis 配置文件路径 -->
<property name="configLocation" value="classpath:/mybatis/config.xml" />
</bean>
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
<!-- 这个执行器会批量执行更新语句, 还有 SIMPLE 和 REUSE -->
<!-- <constructor-arg index="1" value="BATCH" /> -->
</bean>
<!-- 扫描 basePackage 接口 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 映射器接口文件的包路径, -->
<property name="basePackage" value="com.xhy.asp.one.dao" />
</bean>
<!-- 使用 annotation 定义事务 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"
proxy-target-class="true" />
<!-- 数据源配置, 使用 Tomcat JDBC 连接池 -->
<!-- 阿里巴巴 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<!-- 基本属性 url 、 user 、 password -->
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- 配置初始化大小、最小、最大 -->
<property name="initialSize" value="${ds.initialSize}" />
<property name="minIdle" value="${ds.minIdle}" />
<property name="maxActive" value="${ds.maxActive}" />
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="${ds.maxWait}" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="${ds.timeBetweenEvictionRunsMillis}" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="${ds.minEvictableIdleTimeMillis}" />
<property name="validationQuery" value="SELECT 'x'" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<!-- 打开 PSCache ,并且指定每个连接上 PSCache 的大小 -->
<property name="poolPreparedStatements" value="false" />
<property name="maxPoolPreparedStatementPerConnectionSize"
value="20" />
<!-- 配置监控统计拦截的 filters -->
<property name="filters" value="stat" />
</bean>
<!-- <bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource"
destroy-method="close"> Connection Info <property name="driverClassName"
value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property
name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}"
/> Connection Pooling Info <property name="maxActive" value="${jdbc.pool.maxActive}"
/> <property name="maxIdle" value="${jdbc.pool.maxIdle}" /> <property name="minIdle"
value="0" /> <property name="defaultAutoCommit" value="false" /> </bean> -->
<!-- production 环境 -->
<context:property-placeholder
ignore-unresolvable="true" file-encoding="utf-8" location="classpath:jdbc.properties" />
</beans>
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/2015_repair?useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=
##DataSource Global Setting
#配置初始化大小、最小、最大
ds.initialSize=1
ds.minIdle=1
ds.maxActive=20
#配置获取连接等待超时的时间
ds.maxWait=60000
#配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
ds.timeBetweenEvictionRunsMillis=60000
#配置一个连接在池中最小生存的时间,单位是毫秒
ds.minEvictableIdleTimeMillis=300000