org.springframework.boot.autoconfigure.jdbc.DataSourceProperties#getUsername ( )源码实例Demo

下面列出了org.springframework.boot.autoconfigure.jdbc.DataSourceProperties#getUsername ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: spring-boot-react-blog   文件: DatabaseConfig.java
@Bean(destroyMethod = "close")
public HikariDataSource dataSource(DataSourceProperties dataSourceProperties, ApplicationProperties applicationProperties) {
    log.debug("Configuring Datasource");

    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName(dataSourceProperties.getDriverClassName());

    config.addDataSourceProperty("url", dataSourceProperties.getUrl());
    if (dataSourceProperties.getUsername() != null) {
        config.addDataSourceProperty("user", dataSourceProperties.getUsername());
    } else {
        config.addDataSourceProperty("user", ""); // HikariCP doesn't allow null user
    }
    if (dataSourceProperties.getPassword() != null) {
        config.addDataSourceProperty("password", dataSourceProperties.getPassword());
    } else {
        config.addDataSourceProperty("password", ""); // HikariCP doesn't allow null password
    }
    return new HikariDataSource(config);
}
 
源代码2 项目: c2mon   文件: ConfigDataSourceConfig.java
@Bean
 public DataSource configurationDataSource(@Autowired DataSourceProperties configDataSourceProperties) {

String url = configDataSourceProperties.getUrl();

   // A simple inspection is done on the JDBC URL to deduce whether to create an in-memory
   // in-process database, start a file-based externally visible database or connect to
   // an external database.
   if (url.contains("hsql")) {
     String username = configDataSourceProperties.getUsername();
     String password = configDataSourceProperties.getPassword();
       
     return HsqlDatabaseBuilder.builder()
                .url(url)
                .username(username)
                .password(password)
                .script(new ClassPathResource("sql/config-schema-hsqldb.sql"))
                .build().toDataSource();
   } else {
   	return configDataSourceProperties.initializeDataSourceBuilder().build();
   }
 }
 
源代码3 项目: c2mon   文件: HistoryDataSourceConfig.java
@Bean
@ConfigurationProperties("c2mon.server.history.jdbc")
public DataSource historyDataSource(@Autowired DataSourceProperties historyDataSourceProperties) {
  String url = historyDataSourceProperties.getUrl();

  if (url.contains("hsql")) {
    String username = historyDataSourceProperties.getUsername();
    String password = historyDataSourceProperties.getPassword();
    return HsqlDatabaseBuilder.builder()
               .url(url)
               .username(username)
               .password(password)
               .script(new ClassPathResource("sql/history-schema-hsqldb.sql")).build()
               .toDataSource();
  } else {
    return historyDataSourceProperties.initializeDataSourceBuilder().build();
  }
}
 
源代码4 项目: c2mon   文件: CacheDataSourceConfig.java
@Bean
public DataSource cacheDataSource(@Autowired DataSourceProperties cacheDataSourceProperties) {
  String url = cacheDataSourceProperties.getUrl();

  // A simple inspection is done on the JDBC URL to deduce whether to create an in-memory
  // in-process database, start a file-based externally visible database or connect to
  // an external database.
  if (url.contains("hsql")) {
    String username =  cacheDataSourceProperties.getUsername();
    String password =  cacheDataSourceProperties.getPassword();
    return HsqlDatabaseBuilder.builder().url(url).username(username).password(password)
     .script(new ClassPathResource("sql/cache-schema-hsqldb.sql")).build().toDataSource();
  } else {
     return cacheDataSourceProperties.initializeDataSourceBuilder().build();
  }
}
 
源代码5 项目: expper   文件: DatabaseConfiguration.java
@Bean(destroyMethod = "close")
@ConditionalOnExpression("#{!environment.acceptsProfiles('cloud') && !environment.acceptsProfiles('heroku')}")
public DataSource dataSource(DataSourceProperties dataSourceProperties, JHipsterProperties jHipsterProperties) {
    log.debug("Configuring Datasource");
    if (dataSourceProperties.getUrl() == null) {
        log.error("Your database connection pool configuration is incorrect! The application" +
                " cannot start. Please check your Spring profile, current profiles are: {}",
            Arrays.toString(env.getActiveProfiles()));

        throw new ApplicationContextException("Database connection pool is not configured correctly");
    }
    HikariConfig config = new HikariConfig();
    config.setDataSourceClassName(dataSourceProperties.getDriverClassName());
    config.addDataSourceProperty("url", dataSourceProperties.getUrl());
    if (dataSourceProperties.getUsername() != null) {
        config.addDataSourceProperty("user", dataSourceProperties.getUsername());
    } else {
        config.addDataSourceProperty("user", ""); // HikariCP doesn't allow null user
    }
    if (dataSourceProperties.getPassword() != null) {
        config.addDataSourceProperty("password", dataSourceProperties.getPassword());
    } else {
        config.addDataSourceProperty("password", ""); // HikariCP doesn't allow null password
    }

    if (metricRegistry != null) {
        config.setMetricRegistry(metricRegistry);
    }
    return new HikariDataSource(config);
}