Spring使用DriverManagerDataSource和C3P0分别配置MySql6.0.6数据源
首先,看一下项目路径
先说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-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <!-- 导入属性文件 -->
<context:property-placeholder location="classpath:properties/jdbc.properties"/> <bean id="dataSourceSpring" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="username" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.pwd}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="driverClassName" value="${jdbc.driver}"></property>
</bean>
<bean id="dataSourceC3p0" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="root"></property>
<property name="password" value="1234"></property>
<property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/test?serverTimezone=Hongkong"></property>
<property name="driverClass" value="com.mysql.cj.jdbc.Driver"></property>
</bean>
</beans>
bean的id使用不同的来进行区分,主要区别在于class指向不同,dataSourceSpring 并没有连接池作用,另一个使用了C3P0进行配置
properties文件
jdbc.user=root
jdbc.pwd=1234
jdbc.url=jdbc:mysql://127.0.0.1:3306/test?serverTimezone=Hongkong
jdbc.driver=com.mysql.cj.jdbc.Driver
main方法文件
package com.tse.test; import java.sql.SQLException; import javax.sql.DataSource; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main {
public static void main(String[] args) throws SQLException {
ApplicationContext aContext = new ClassPathXmlApplicationContext("com/tse/spring/applicationContext_jdbc.xml");
DataSource dataSources = (DataSource) aContext.getBean("dataSourceSpring");
DataSource dataSources1 = (DataSource) aContext.getBean("dataSourceC3p0");
System.out.println(dataSources.getConnection());
System.out.println(dataSources1.getConnection());
}
}
执行结果
九月 13, 2018 12:04:35 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1a6c5a9e: startup date [Thu Sep 13 12:04:35 CST 2018]; root of context hierarchy
九月 13, 2018 12:04:35 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [com/tse/spring/applicationContext_jdbc.xml]
九月 13, 2018 12:04:35 下午 org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
信息: Loaded JDBC driver: com.mysql.cj.jdbc.Driver
九月 13, 2018 12:04:35 下午 com.mchange.v2.log.MLog <clinit>
信息: MLog clients using java 1.4+ standard logging.
九月 13, 2018 12:04:35 下午 com.mchange.v2.c3p0.C3P0Registry banner
信息: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
Thu Sep 13 12:04:36 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
com.mysql.cj.jdbc.ConnectionImpl@1ffe63b9
九月 13, 2018 12:04:36 下午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge13c9x1m0nuop1yft6fk|2173f6d9, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.cj.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge13c9x1m0nuop1yft6fk|2173f6d9, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://127.0.0.1:3306/test?serverTimezone=Hongkong, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
Thu Sep 13 12:04:36 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Thu Sep 13 12:04:36 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Thu Sep 13 12:04:36 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
com.mchange.v2.c3p0.impl.NewProxyConnection@769f71a9
代码上传位置,请自行获取
https://download.csdn.net/download/lijian0420/10664103
Spring使用DriverManagerDataSource和C3P0分别配置MySql6.0.6数据源的更多相关文章
- ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存
ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存 hibernate : Hibernate是一个持久层框架,经常访问物理数据库 ...
- spring boot配置MySQL8.0 Druid数据源
创建spring boot项目,在pom中添加相应依赖 <!--web--> <dependency> <groupId>org.springframework.b ...
- Spring+SpringMVC+MyBatis+LogBack+C3P0+Maven+Git小结(转)
摘要 出于兴趣,想要搭建一个自己的小站点,目前正在积极的准备环境,利用Spring+SpringMVC+MyBatis+LogBack+C3P0+Maven+Git,这里总结下最近遇到的一些问题及解决 ...
- Spring 数据源配置二:多数据源
通过上一节 Spring 数据源配置一: 单一数据源 我们了解单一数据源的配置, 这里我们继续多个数据源的配置 如下(applicationContent.xml 内容) 一: Spring ...
- Spring IOC之基于JAVA的配置
基础内容:@Bean 和 @Configuration 在Spring中新的支持java配置的核心组件是 @Configuration注解的类和@Bean注解的方法. @Bean注解被用于表明一个方法 ...
- Spring事物管理--相关要点及配置事物管理器
事务的四大特征 1.原子性:一个事务中所有对数据库的操作是一个不可分割的操作序列,要么全做要么全不做 2.一致性:数据不会因为事务的执行而遭到破坏 3.隔离性:一个事物的执行,不受其他事务的干扰,即并 ...
- 8 -- 深入使用Spring -- 1...4 重写占位符配置器
8.1.5 重写占位符配置器 (PropertyOverrideConfigurer) PropertyOverrideConfigurer是Spring提供的另一个容器后处理器.PropertyOv ...
- 8 -- 深入使用Spring -- 1...4 属性占位符配置器
8.1.4 属性占位符配置器 PropertyPlaceholderConfigurer 是一个容器后处理器,负责读取Properties属性文件里的属性值,并将这些属性值设置成Spring配置文件的 ...
- Spring Security(08)——intercept-url配置
http://elim.iteye.com/blog/2161056 Spring Security(08)--intercept-url配置 博客分类: spring Security Spring ...
随机推荐
- /bin/bash: jar: command not found(转载)
转自:http://blog.csdn.net/zhangdaiscott/article/details/23138023 /bin/bash: jar: command not found 解决办 ...
- 用 python 写一个模拟玩家移动的示例
实例:二维矢量模拟玩家移动 在游戏中,一般使用二维矢量保存玩家的位置,使用矢量计算可以计算出玩家移动的位置,下面的 demo 中,首先实现二维矢量对象,接着构造玩家对象,最后使用矢量对象和玩家对象共同 ...
- Django day 36 支付宝支付,微信推送
一:支付宝支付, 二:微信推送
- 慕课网2-5 编程练习:通过jQuery通配符选择器进行文字变色
2-5 编程练习 请请使用*选择器将div标签中的字体颜色变成红色 效果图: 任务 (1)使用通配符选择器 (2)使用jQuery的.css()方法设置样式,语法css('属性 '属性值') 参考代码 ...
- 洛谷P3383 【模板】线性筛素数 (埃拉托斯特尼筛法)
题目描述 如题,给定一个范围N,你需要处理M个某数字是否为质数的询问(每个数字均在范围1-N内) 输入输出格式 输入格式: 第一行包含两个正整数N.M,分别表示查询的范围和查询的个数. 接下来M行每行 ...
- ACM_错排(递推dp)
RPG的错排 Time Limit: 2000/1000ms (Java/Others) Problem Description: 今年暑假GOJ集训队第一次组成女生队,其中有一队叫RPG,但做为集训 ...
- SimpleDataFormat详解
[转]SimpleDateFormat使用详解 public class SimpleDateFormat extends DateFormat SimpleDateFormat 是一个以国别敏感的方 ...
- java邮件发送工具
最近在web项目中,客户端注册时需要通过邮箱验证,服务器就需要向客户端发送邮件,我把发送邮件的细节进行了简易的封装: 在maven中需要导入: <!--Email--> <depen ...
- hihocoder offer收割编程练习赛13 D 骑士游历
思路: 矩阵快速幂. 实现: #include <iostream> #include <cstdio> #include <vector> using names ...
- 【sqli-labs】 less63 GET -Challenge -Blind -130 queries allowed -Variation2 (GET型 挑战 盲注 只允许130次查询 变化2)
引号闭合 http://192.168.136.128/sqli-labs-master/Less-63/?id=1' or '1'='1 剩下的和Less62一样