Integration of Springboot and C3P0

Source: Internet
Author: User

First create the C3P0 data source class

 PackageCom.example.demo.config;ImportJavax.sql.DataSource;ImportOrg.mybatis.spring.SqlSessionFactoryBean;ImportOrg.springframework.beans.factory.annotation.Qualifier;ImportOrg.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;Importorg.springframework.boot.context.properties.ConfigurationProperties;ImportOrg.springframework.context.annotation.Bean;Importorg.springframework.context.annotation.Configuration;Importorg.springframework.context.annotation.Primary; @Configuration Public classc3p0datasourceconfig {@Bean (name= "DataSource") @Qualifier (value= "DataSource")//qualifier descriptors can be injected in addition to names, but finer-grained control over how to select candidates@Primary//distinguish the primary data source with @primary@ConfigurationProperties (prefix= "c3p0")//attribute value in the specified configuration file with prefix c3p0     PublicDataSource DataSource () {returnDatasourcebuilder.create (). Type (Com.mchange.v2.c3p0.ComboPooledDataSource.class). build ();//Create a data source    }    /*** Return to Sqlsessionfactory*/@Bean PublicSqlsessionfactorybean Sqlsessionfactorybean () {Sqlsessionfactorybean sqlsessionfactory=NewSqlsessionfactorybean ();        Sqlsessionfactory.setdatasource (DataSource ()); returnsqlsessionfactory; }}

Then configure Application.properties

C3p0.jdbcurl=jdbc:mysql:///testcrm?characterencoding=utf8c3p0.user=Rootc3p0.password =123c3p0.driverclass=com.mysql.jdbc.driver

Integration of Springboot and C3P0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.