All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.telewave.logger.config.DataSourceConfig Maven / Gradle / Ivy

The newest version!
package com.telewave.logger.config;

import com.mchange.v2.c3p0.DriverManagerDataSource;
import com.telewave.logger.page.JdbcTemplageSupport;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;

/**
 * Created by aiowang on 2018/7/20.
 */
@Configuration
public class DataSourceConfig {

    @Value("${spring.datasource.hikari.twloggerh2.jdbc-url:jdbc:h2:file:./twlogger_h2/twlogger}")
    private String url;
    @Value("${spring.datasource.hikari.twloggerh2.driver-class-name:org.h2.Driver}")
    private String driverclassname;
    @Value("${spring.datasource.hikari.twloggerh2.username:admin}")
    private String username;
    @Value("${spring.datasource.hikari.twloggerh2.password:admin}")
    private String password;


    DriverManagerDataSource getDataSource(){
        DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
        driverManagerDataSource.setJdbcUrl(url);
        driverManagerDataSource.setDriverClass(driverclassname);
        driverManagerDataSource.setUser(username);
        driverManagerDataSource.setPassword(password);
        return driverManagerDataSource;
    }
/*
    @Bean(name="twlogger2jdbc")
    *//*    @Qualifier("twloggerh2DataSource")
    @Primary*//*
    public JdbcTemplate jdbcTemplate(){
        JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());
        return jdbcTemplate;

    }*/

    @Bean(name="twlogger2jdbc")
    /*    @Qualifier("twloggerh2DataSource")
    @Primary*/
    public NamedParameterJdbcTemplate namedParameterJdbcTemplate(){
        NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(getDataSource());
        return namedParameterJdbcTemplate;

    }

    @Bean(name="jdbcTemplageSupport")
    public JdbcTemplageSupport jdbcTemplageSupport(NamedParameterJdbcTemplate namedParameterJdbcTemplate){
        JdbcTemplate jdbcTemplate =namedParameterJdbcTemplate.getJdbcTemplate();
        return new JdbcTemplageSupport(jdbcTemplate);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy