springBoot和c3p0的整合
首先创建c3p0的数据源类
package com.example.demo.config; import javax.sql.DataSource; import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary; @Configuration
public class C3p0DataSourceConfig { @Bean(name="dataSource")
@Qualifier(value="dataSource")//限定描述符除了能根据名字进行注入,但能进行更细粒度的控制如何选择候选者
@Primary//用@Primary区分主数据源
@ConfigurationProperties(prefix="c3p0")//指定配置文件中,前缀为c3p0的属性值
public DataSource dataSource(){
return DataSourceBuilder.create().type(com.mchange.v2.c3p0.ComboPooledDataSource.class).build();//创建数据源
}
/**
*返回sqlSessionFactory
*/
@Bean
public SqlSessionFactoryBean sqlSessionFactoryBean(){
SqlSessionFactoryBean sqlSessionFactory = new SqlSessionFactoryBean();
sqlSessionFactory.setDataSource(dataSource());
return sqlSessionFactory;
}
}
然后配置application.properties
c3p0.jdbcUrl=jdbc:mysql:///testcrm?characterEncoding=utf8
c3p0.user=root
c3p0.password=123
c3p0.driverClass=com.mysql.jdbc.Driver
springBoot和c3p0的整合的更多相关文章
- Java之SpringBoot自定义配置与整合Druid
Java之SpringBoot自定义配置与整合Druid SpringBoot配置文件 优先级 前面SpringBoot基础有提到,关于SpringBoot配置文件可以是properties或者是ya ...
- springboot 使用c3p0数据库连接池的方法
使用springboot开发时,默认使用内置的tomcat数据库连接池,经常碰到这种情况:运行时间一长,数据库连接中断了.所以使用c3p0连接池吧. 引入的maven依赖: <dependenc ...
- springboot+jpa+mysql+swagger整合
Springboot+jpa+MySQL+swagger整合 创建一个springboot web项目 <dependencies> <dependency> < ...
- Springboot 2.0.4 整合Mybatis出现异常Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
在使用Springboot 2.0.4 整合Mybatis的时候出现异常Property 'sqlSessionFactory' or 'sqlSessionTemplate' are require ...
- springboot 使用c3p0数据库连接池
springboot 使用c3p0数据库连接池的方法 本文转自:http://www.cnblogs.com/xiaosiyuan/p/6255292.html 使用springboot开发时,默认 ...
- SpringBoot+SpringMVC+MyBatis快速整合搭建
作为开发人员,大家都知道,SpringBoot是基于Spring4.0设计的,不仅继承了Spring框架原有的优秀特性,而且还通过简化配置来进一步简化了Spring应用的整个搭建和开发过程.另外Spr ...
- SpringBoot与PageHelper的整合示例详解
SpringBoot与PageHelper的整合示例详解 1.PageHelper简介 PageHelper官网地址: https://pagehelper.github.io/ 摘要: com.gi ...
- SpringBoot学习- 4、整合JWT
SpringBoot学习足迹 1.Json web token(JWT)是为了网络应用环境间传递声明而执行的一种基于JSON的开发标准(RFC 7519),该token被设计为紧凑且安全的,特别适用于 ...
- SpringBoot学习- 3、整合MyBatis
SpringBoot学习足迹 1.下载安装一个Mysql数据库及管理工具,同类工具很多,随便找一个都可以,我在windows下做测试项目习惯使用的是haosql 它内部集成了MySql-Front管理 ...
随机推荐
- KeyguardSimPinView
/* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Versi ...
- Codeforces 1105C: Ayoub and Lost Array(递推)
time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: sta ...
- js ·节点的知识点
1. DOM document object model (1) 节点树状图 Document>documentElement>body>tagname 2. 我们常用的节点类型 元 ...
- C#编写CLR函数
本案例在VS2017环境中开发: 1.新建项目,“数据库项目”,添加 UserDefinedFunctions.cs类文件,代码如下: using System; using System.Data; ...
- jQuery基础之二
jQuery基础之二 jQuery的中文文档十分详细,并且权威.W3C的jQuery文档更加简单实用. jQuery 1.9.0 jQuery中文文档W3C的jQuery文档 jQuery操作DO ...
- 试写foxit reader的ConvertToPDF功能的wrapper
相比于直接fuzzing大型程序本身,针对程序的某一特定功能写wrapper后再fuzzing则要高效的多.网上搜了下,仅有两篇关于foxit reader的wrapper文章,一个用python,另 ...
- legend_noa 的 EMACS配置
(defun my-c-mode-auto-pair() (interactive) (make-local-variable'skeleton-pair-alist) (setq skeleton- ...
- 手机游戏引擎 Cocos
Cocos是全球最受欢迎的移动游戏开发解决方案,整合了Cocos 2d-x.Cocos 2d-js.Cocos Studio.Cocos Code IDE等框架及工具,无论您是开发新手还是行业资深人士 ...
- vue-cli项目在IE下运行钩子函数抛出异常“ReferenceError: “Promise”未定义"”的解决办法
兼容IE是个坑,低版本IE很多都没法跑起来 问题现象:vue-cli项目在IE下运行,会在钩子函数出现 ReferenceError: “Promise”未定义 解决办法: step1:安装最新的we ...
- Defender 防卫者
发售年份 1980 平台 街机 开发商 Williams 类型 射击 https://www.youtube.com/watch?v=gss3lxeqCok