1.先到(http://www.mvnrepository.com/)Maven网址找到C3P0的数据源依赖包
<!-- https://mvnrepository.com/artifact/com.mchange/c3p0 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
2.在Spring里面进行配置信息
<!--配置数据源-->
<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="com.mysql.cj.jdbc.Driver"></property> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ot?serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true"></property> <property name="user" value="root"></property> <property name="password" value="123456"></property> <property name="minPoolSize" value="3"></property> <property name="maxPoolSize" value="15"></property> <property name="initialPoolSize" value="3"></property> </bean>
3.绑定配置数据源的id="myDataSource" 在下面的文件ref中绑定
<bean id="mySqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="myDataSource"></property>
<property name="mapperLocations" value="classpath*:Mapper/*.xml"></property>
</bean>
1.先到(http://www.mvnrepository.com/)Maven网址找到DBCP的数据源依赖包
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.5.0</version>
</dependency>
2.在Spring里面进行配置信息
<bean id="myDataSource-dbcp" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/ot?serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true"></property>
<property name="username" value="root"></property>
<property name="password" value="123456"></property>
</bean>
3.绑定配置数据源的id="myDataSource-dbcp" 在下面的文件ref中绑定
<bean id="mySqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="myDataSource-dbcp"></property>
<property name="mapperLocations" value="classpath*:Mapper/*.xml"></property>
</bean>
1.先到(http://www.mvnrepository.com/)Maven网址找到Druid的数据源依赖包
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.10</version>
</dependency>
2.在Spring里面进行配置信息
<bean id="Druid" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/ot?serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true"></property>
<property name="username" value="root"/>
<property name="password" value="123456"/>
</bean>
3.绑定配置数据源的id="Druid" 在下面的文件ref中绑定
<bean id="mySqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="Druid"></property>
<property name="mapperLocations" value="classpath*:Mapper/*.xml"></property>
</bean>
myDataSource-dbcp