Example usage for org.springframework.boot.autoconfigure.jdbc DataSourceProperties getUsername

List of usage examples for org.springframework.boot.autoconfigure.jdbc DataSourceProperties getUsername

Introduction

In this page you can find the example usage for org.springframework.boot.autoconfigure.jdbc DataSourceProperties getUsername.

Prototype

public String getUsername() 

Source Link

Document

Return the configured username or null if none was configured.

Usage

From source file:com.teradata.benchto.driver.jdbc.MultipleDataSourcesConfiguration.java

private DataSource createDataSource(DataSourceProperties properties) {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(properties.getDriverClassName());
    dataSource.setUrl(properties.getUrl());
    dataSource.setUsername(properties.getUsername());
    dataSource.setPassword(properties.getPassword());
    return dataSource;
}

From source file:com.todo.backend.config.DatabaseConfiguration.java

@Bean(destroyMethod = "close")
public DataSource dataSource(DataSourceProperties dataSourceProperties, CustomProperties customProperties) {

    log.debug("Initializing datasource...");

    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
    config.addDataSourceProperty("url", dataSourceProperties.getUrl());
    config.addDataSourceProperty("user", dataSourceProperties.getUsername());
    config.addDataSourceProperty("password",
            dataSourceProperties.getPassword() == null ? "" : dataSourceProperties.getPassword());

    // mysql specific
    config.addDataSourceProperty("cachePrepStmts", customProperties.getDatasource().isCachePrepStmts());
    config.addDataSourceProperty("prepStmtCacheSize", customProperties.getDatasource().getPrepStmtCacheSize());
    config.addDataSourceProperty("prepStmtCacheSqlLimit",
            customProperties.getDatasource().getPrepStmtCacheSqlLimit());
    config.addDataSourceProperty("useServerPrepStmts", customProperties.getDatasource().isUseServerPrepStmts());

    return new HikariDataSource(config);
}