Java Code Examples for org.springframework.boot.autoconfigure.jdbc.DataSourceProperties#setUrl()

The following examples show how to use org.springframework.boot.autoconfigure.jdbc.DataSourceProperties#setUrl() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataSourceConfig.java    From haven-platform with Apache License 2.0 6 votes vote down vote up
@Bean
@Primary
public DataSourceProperties dataSourceProperties() {
    DataSourceProperties properties = new DataSourceProperties();
    properties.setInitialize(false);
    // dbName.serviceName example: user-db.mysql (we must )
    final String serviceId = environment.getProperty(MYSQL_SERVICE_ID);
    if (discoveryClient != null && serviceId != null) {
        List<ServiceInstance> instances = discoveryClient.getInstances(serviceId);
        if (!instances.isEmpty()) {
            properties.setUrl(getJdbcUrl(instances, fetchDBName(serviceId)));
        }  else {
            LOGGER.warn("there is no services with id {} in service discovery", serviceId);
        }
    }
    return properties;
}
 
Example 2
Source File: TaskServiceUtilsTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Test
public void testDatabasePropUpdate() {
	TaskDefinition taskDefinition = new TaskDefinition("testTask", "testApp");
	DataSourceProperties dataSourceProperties = new DataSourceProperties();
	dataSourceProperties.setUsername("myUser");
	dataSourceProperties.setDriverClassName("myDriver");
	dataSourceProperties.setPassword("myPassword");
	dataSourceProperties.setUrl("myUrl");
	TaskDefinition definition = TaskServiceUtils.updateTaskProperties(
			taskDefinition,
			dataSourceProperties);

	assertThat(definition.getProperties().size()).isEqualTo(5);
	assertThat(definition.getProperties().get("spring.datasource.url")).isEqualTo("myUrl");
	assertThat(definition.getProperties().get("spring.datasource.driverClassName")).isEqualTo("myDriver");
	assertThat(definition.getProperties().get("spring.datasource.username")).isEqualTo("myUser");
	assertThat(definition.getProperties().get("spring.datasource.password")).isEqualTo("myPassword");
}
 
Example 3
Source File: TaskanaWildFlyApplication.java    From taskana with Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
@ConfigurationProperties(prefix = "datasource")
public DataSourceProperties dataSourceProperties() {
  DataSourceProperties props = new DataSourceProperties();
  props.setUrl(
      "jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0;INIT=CREATE SCHEMA IF NOT EXISTS "
          + schemaName);
  return props;
}
 
Example 4
Source File: ExampleRestApplication.java    From taskana with Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
@ConfigurationProperties(prefix = "datasource")
public DataSourceProperties dataSourceProperties() {
  DataSourceProperties props = new DataSourceProperties();
  props.setUrl(
      "jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0;INIT=CREATE SCHEMA IF NOT EXISTS "
          + schemaName);
  return props;
}
 
Example 5
Source File: ExampleDocumentationApplication.java    From taskana with Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
@ConfigurationProperties(prefix = "datasource")
public DataSourceProperties dataSourceProperties() {
  DataSourceProperties props = new DataSourceProperties();
  props.setUrl(
      "jdbc:h2:mem:taskana;IGNORECASE=TRUE;LOCK_MODE=0;INIT=CREATE SCHEMA IF NOT EXISTS "
          + schemaName);
  return props;
}
 
Example 6
Source File: GcpCloudSqlAutoConfiguration.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Bean
@Primary
@ConditionalOnBean(CloudSqlJdbcInfoProvider.class)
public DataSourceProperties cloudSqlDataSourceProperties(
		GcpCloudSqlProperties gcpCloudSqlProperties,
		DataSourceProperties properties,
		GcpProperties gcpProperties,
		CloudSqlJdbcInfoProvider cloudSqlJdbcInfoProvider) {

	if (StringUtils.isEmpty(properties.getUsername())) {
		properties.setUsername("root");
		LOGGER.warn("spring.datasource.username is not specified. "
				+ "Setting default username.");
	}
	if (StringUtils.isEmpty(properties.getDriverClassName())) {
		properties.setDriverClassName(cloudSqlJdbcInfoProvider.getJdbcDriverClass());
	}
	else {
		LOGGER.warn("spring.datasource.driver-class-name is specified. " +
						"Not using generated Cloud SQL configuration");
	}

	if (StringUtils.hasText(properties.getUrl())) {
		LOGGER.warn("Ignoring provided spring.datasource.url. Overwriting it based on the " +
				"spring.cloud.gcp.sql.instance-connection-name.");
	}
	properties.setUrl(cloudSqlJdbcInfoProvider.getJdbcUrl());

	if (gcpCloudSqlProperties.getCredentials().getEncodedKey() != null) {
		setCredentialsEncodedKeyProperty(gcpCloudSqlProperties);
	}
	else {
		setCredentialsFileProperty(gcpCloudSqlProperties, gcpProperties);
	}

	CoreSocketFactory.setApplicationName("spring-cloud-gcp-sql/"
			+ this.getClass().getPackage().getImplementationVersion());

	return properties;
}