首先,看一下项目路径

先说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数据源的更多相关文章

  1. ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存

    ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存 hibernate  : Hibernate是一个持久层框架,经常访问物理数据库 ...

  2. spring boot配置MySQL8.0 Druid数据源

    创建spring boot项目,在pom中添加相应依赖 <!--web--> <dependency> <groupId>org.springframework.b ...

  3. Spring+SpringMVC+MyBatis+LogBack+C3P0+Maven+Git小结(转)

    摘要 出于兴趣,想要搭建一个自己的小站点,目前正在积极的准备环境,利用Spring+SpringMVC+MyBatis+LogBack+C3P0+Maven+Git,这里总结下最近遇到的一些问题及解决 ...

  4. Spring 数据源配置二:多数据源

    通过上一节  Spring 数据源配置一: 单一数据源  我们了解单一数据源的配置, 这里我们继续多个数据源的配置 如下(applicationContent.xml 内容) 一:  Spring   ...

  5. Spring IOC之基于JAVA的配置

    基础内容:@Bean 和 @Configuration 在Spring中新的支持java配置的核心组件是 @Configuration注解的类和@Bean注解的方法. @Bean注解被用于表明一个方法 ...

  6. Spring事物管理--相关要点及配置事物管理器

    事务的四大特征 1.原子性:一个事务中所有对数据库的操作是一个不可分割的操作序列,要么全做要么全不做 2.一致性:数据不会因为事务的执行而遭到破坏 3.隔离性:一个事物的执行,不受其他事务的干扰,即并 ...

  7. 8 -- 深入使用Spring -- 1...4 重写占位符配置器

    8.1.5 重写占位符配置器 (PropertyOverrideConfigurer) PropertyOverrideConfigurer是Spring提供的另一个容器后处理器.PropertyOv ...

  8. 8 -- 深入使用Spring -- 1...4 属性占位符配置器

    8.1.4 属性占位符配置器 PropertyPlaceholderConfigurer 是一个容器后处理器,负责读取Properties属性文件里的属性值,并将这些属性值设置成Spring配置文件的 ...

  9. Spring Security(08)——intercept-url配置

    http://elim.iteye.com/blog/2161056 Spring Security(08)--intercept-url配置 博客分类: spring Security Spring ...

随机推荐

  1. 搞笑代码注释,佛祖保佑 永无BUG

    佛祖保佑 永无BUG 上传图片即可生成字符画,效果还不错, https://www.fontke.com/tool/image2ascii/ 神注释大全 https://github.com/Blan ...

  2. ADSI和其他内容

    ADSI (Active Directory Services Interface)是Microsoft推出的一项技术,它统一了许多底层服务的编程接口,程序员可以使用一致的对象技术来访问这些底层服务. ...

  3. [转]Linux系统调用--fcntl函数详解

    功能描述:根据文件描述词来操作文件的特性. 文件控制函数          fcntl -- file control头文件: #include <unistd.h> #include & ...

  4. Hdu 4738 Caocao's Bridges (连通图+桥)

    题目链接: Hdu 4738 Caocao's Bridges 题目描述: 有n个岛屿,m个桥,问是否可以去掉一个花费最小的桥,使得岛屿边的不连通? 解题思路: 去掉一个边使得岛屿不连通,那么去掉的这 ...

  5. 二分搜索 HDOJ 2675 Equation Again

    题目传送门 /* 二分搜索:式子两边取对数,将x提出来,那么另一边就是一个常数了,函数是:lnx/x.二分搜索x,注意要两次 */ #include <cstdio> #include & ...

  6. CDH搭建Hadoop分布式服务器集群(java新手小白)

    1首先对于一个java还白的小白,先理解CDH与Hadoop的关系 一.Hadoop版本选择. Hadoop大致可分为Apache Hadoop和第三方发行第三方发行版Hadoop,考虑到Hadoop ...

  7. 预采订单管理接收来源App数据

  8. BPI-MI1刷Andorid的启动卡之后上网的步骤(以太网&&WIFI)

    BPI-MI1刷Andorid的启动卡之后上网的步骤(以太网&&WIFI) 2017/9/19 16:57 01刷Android的默认启动界面.png 02打开英文模式下的设置Sett ...

  9. 鼠标拖拽移动Java界面组件

    默认的,Frame或者JFrame自身已经实现了鼠标拖拽标题栏移动窗口的功能. 只是,当你不满意java的JFrame样式,隐藏了标题栏和边框,又或者干脆直接使用JWindow,那你又该怎么实现鼠标拖 ...

  10. LDA主题模型(理解篇)

    何谓“主题”呢?望文生义就知道是什么意思了,就是诸如一篇文章.一段话.一个句子所表达的中心思想.不过从统计模型的角度来说, 我们是用一个特定的词频分布来刻画主题的,并认为一篇文章.一段话.一个句子是从 ...