本文整理匯總了Java中org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder.build方法的典型用法代碼示例。如果您正苦於以下問題:Java DataSourceBuilder.build方法的具體用法?Java DataSourceBuilder.build怎麽用?Java DataSourceBuilder.build使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder
的用法示例。
在下文中一共展示了DataSourceBuilder.build方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dataSource
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; //導入方法依賴的package包/類
@Primary
@Bean(destroyMethod = "close")
public DataSource dataSource() {
final EmbeddedMysql embeddedMysql = embeddedMysql(); // make sure embeddedMySql is started.
Map<String, String> params = ImmutableMap.<String, String>builder()
.put("profileSQL", String.valueOf(false))
.put("generateSimpleParameterMetadata", String.valueOf(true))
.build();
final String url = String.format("jdbc:mysql://localhost:%d/%s?%s",
embeddedMysql.getConfig().getPort(),
SCHEMA_NAME,
Joiner.on("&").withKeyValueSeparator("=").join(params));
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.username(embeddedMysql.getConfig().getUsername());
dataSourceBuilder.password(embeddedMysql.getConfig().getPassword());
dataSourceBuilder.driverClassName(com.mysql.jdbc.Driver.class.getName());
dataSourceBuilder.url(url);
return dataSourceBuilder.build();
}
示例2: buildDataSource
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; //導入方法依賴的package包/類
/**
* 創建DataSource
*/
@SuppressWarnings("unchecked")
public DataSource buildDataSource(Map<String, Object> dsMap) {
try {
Object type = dsMap.get("type");
if (type == null)
type = DATASOURCE_TYPE_DEFAULT;// 默認DataSource
Class<? extends DataSource> dataSourceType;
dataSourceType = (Class<? extends DataSource>) Class.forName((String) type);
String driverClassName = dsMap.get("driverClassName").toString();
String url = dsMap.get("url").toString();
String username = dsMap.get("username").toString();
String password = dsMap.get("password").toString();
DataSourceBuilder factory = DataSourceBuilder.create().driverClassName(driverClassName).url(url)
.username(username).password(password).type(dataSourceType);
return factory.build();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
示例3: buildDataSource
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; //導入方法依賴的package包/類
/**
* 創建DataSource
*
* @param type
* @param driverClassName
* @param url
* @param username
* @param password
* @return
* @author SHANHY
* @create 2016年1月24日
*/
@SuppressWarnings("unchecked")
public DataSource buildDataSource(Map<String, Object> dsMap) {
try {
Object type = dsMap.get("type");
if (type == null)
type = DATASOURCE_TYPE_DEFAULT;// 默認DataSource
Class<? extends DataSource> dataSourceType;
dataSourceType = (Class<? extends DataSource>) Class.forName((String) type);
String driverClassName = dsMap.get("driver-class-name").toString();
String url = dsMap.get("url").toString();
String username = dsMap.get("username").toString();
String password = dsMap.get("password").toString();
DataSourceBuilder factory = DataSourceBuilder.create().driverClassName(driverClassName).url(url)
.username(username).password(password).type(dataSourceType);
return factory.build();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
示例4: dataSource
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; //導入方法依賴的package包/類
@Bean
@Primary
public DataSource dataSource() {
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.driverClassName(org.sqlite.JDBC.class.getName());
dataSourceBuilder.url("jdbc:sqlite:~amv-access-test.db?journal_mode=wal");
return dataSourceBuilder.build();
}
示例5: dataSource
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; //導入方法依賴的package包/類
@Bean
@Primary
public DataSource dataSource() {
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.driverClassName(org.sqlite.JDBC.class.getName());
dataSourceBuilder.url("jdbc:sqlite:~amv-access-swagger-docs.db?journal_mode=wal");
return dataSourceBuilder.build();
}
示例6: dataSource
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; //導入方法依賴的package包/類
@Bean
public DataSource dataSource() {
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.driverClassName(driverClassName);
dataSourceBuilder.url(url);
dataSourceBuilder.type(HikariDataSource.class);
return dataSourceBuilder.build();
}
示例7: buildDataSourceDev
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; //導入方法依賴的package包/類
@Bean
@Qualifier("dataSource")
public DataSource buildDataSourceDev() {
DataSourceBuilder dsb = DataSourceBuilder.create();
dsb.driverClassName(driver);
dsb.url(url);
dsb.username(username);
dsb.password(password);
return dsb.build();
}
示例8: defaultDataSource
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; //導入方法依賴的package包/類
/**
* Creates the default data source for the application
* @return
*/
private DataSource defaultDataSource() {
DataSourceBuilder dataSourceBuilder = new DataSourceBuilder(this.getClass().getClassLoader())
.driverClassName(properties.getDriverClassName())
.url(properties.getUrl())
.username(properties.getUsername())
.password(properties.getPassword());
if(properties.getType() != null) {
dataSourceBuilder.type(properties.getType());
}
return dataSourceBuilder.build();
}
示例9: dataSource
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; //導入方法依賴的package包/類
@Override
public DataSource dataSource() {
log.info("Running with STAGING profile");
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.url(System.getenv("DATABASE_URL"));
return dataSourceBuilder.build();
}
示例10: dataSource
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; //導入方法依賴的package包/類
@Override
public DataSource dataSource() {
log.info("Running with LOCAL_PG profile");
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.url(env.getProperty("DATABASE_URL"));
return dataSourceBuilder.build();
}
示例11: dataSource
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; //導入方法依賴的package包/類
@Override
public DataSource dataSource() {
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.url(System.getenv("DATABASE_URL"));
return dataSourceBuilder.build();
}
示例12: dataSource
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; //導入方法依賴的package包/類
/*****************************************************************************************************
* Openshift - MySQL
*****************************************************************************************************
MySQL 5.5 database added. Please make note of these credentials:
Root User: adminCUBivEk
Root Password: b4be_AuNYSPh
Database Name: bruxelas
Connection URL: mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/
You can manage your new MySQL database by also embedding phpmyadmin.
The phpmyadmin username and password will be the same as the MySQL credentials above.
*****************************************************************************************************
* Openshift - PhpMyAdmin
*****************************************************************************************************
Please make note of these MySQL credentials again:
Root User: adminCUBivEk
Root Password: b4be_AuNYSPh
URL: https://bruxelas-fabianoggoes.rhcloud.com/phpmyadmin/
*****************************************************************************************************/
@Bean(destroyMethod = "close")
public DataSource dataSource() {
System.out.println( "<<< Profile = prod >>>" );
String host = System.getenv().get("OPENSHIFT_MYSQL_DB_HOST") == null ? "localhost" : System.getenv().get("OPENSHIFT_MYSQL_DB_HOST");
String port = System.getenv().get("OPENSHIFT_MYSQL_DB_PORT") == null ? "3306" : System.getenv().get("OPENSHIFT_MYSQL_DB_PORT");
String user = System.getenv().get("OPENSHIFT_MYSQL_DB_USERNAME") == null ? "bruxelas" : System.getenv().get("OPENSHIFT_MYSQL_DB_USERNAME");
String pass = System.getenv().get("OPENSHIFT_MYSQL_DB_PASSWORD") == null ? "bruxelas" : System.getenv().get("OPENSHIFT_MYSQL_DB_PASSWORD");
String database = "bruxelas";
String url = "jdbc:mysql://" + host + ":" + port + "/" + database + "?autoReconnect=true&useSSL=false";
DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.url(url);
dataSourceBuilder.username(user);
dataSourceBuilder.password(pass);
return dataSourceBuilder.build();
}