本文整理汇总了Java中org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration类的典型用法代码示例。如果您正苦于以下问题:Java DataSourceAutoConfiguration类的具体用法?Java DataSourceAutoConfiguration怎么用?Java DataSourceAutoConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataSourceAutoConfiguration类属于org.springframework.boot.autoconfigure.jdbc包,在下文中一共展示了DataSourceAutoConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; //导入依赖的package包/类
@Before
public void init() {
dbUrl = "h2:mem:testdb-" + new Random().nextInt();
EnvironmentTestUtils.addEnvironment(context,
"spring.datasource.initialize:false",
"spring.datasource.url:jdbc:" + dbUrl);
context.setClassLoader(new HidePackagesClassLoader("com.vladmihalcea.flexypool", "net.ttddyy.dsproxy"));
context.register(DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
TraceAutoConfiguration.class,
SleuthLogAutoConfiguration.class,
SleuthListenerAutoConfiguration.class,
SavingSpanReporterConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
context.refresh();
dataSource = context.getBean(DataSource.class);
spanReporter = context.getBean(CollectingSpanReporter.class);
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:20,代码来源:TracingJdbcEventListenerTests.java
示例2: init
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; //导入依赖的package包/类
@Before
public void init() {
dbUrl = "h2:mem:testdb-" + new Random().nextInt();
EnvironmentTestUtils.addEnvironment(context,
"spring.datasource.initialize:false",
"spring.datasource.url:jdbc:" + dbUrl);
context.setClassLoader(new HidePackagesClassLoader("com.vladmihalcea.flexypool", "com.p6spy"));
context.register(DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
SavingSpanReporterConfiguration.class,
TraceAutoConfiguration.class,
SleuthLogAutoConfiguration.class,
SleuthListenerAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
context.refresh();
dataSource = context.getBean(DataSource.class);
spanReporter = context.getBean(CollectingSpanReporter.class);
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:20,代码来源:TracingQueryExecutionListenerTests.java
示例3: testAddsDatasourceProxyListener
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; //导入依赖的package包/类
@Test
public void testAddsDatasourceProxyListener() {
context.setClassLoader(new HidePackagesClassLoader("com.vladmihalcea.flexypool", "com.p6spy"));
context.register(DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
TraceAutoConfiguration.class,
SleuthLogAutoConfiguration.class,
SleuthListenerAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
context.refresh();
DataSource dataSource = context.getBean(DataSource.class);
ProxyDataSource proxyDataSource = (ProxyDataSource) ((DecoratedDataSource) dataSource).getDecoratedDataSource();
ChainListener chainListener = proxyDataSource.getProxyConfig().getQueryListener();
assertThat(chainListener.getListeners()).extracting("class").contains(TracingQueryExecutionListener.class);
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:17,代码来源:SleuthListenerAutoConfigurationTests.java
示例4: testDecoratedHikariSpecificPropertiesIsSet
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; //导入依赖的package包/类
@Test
public void testDecoratedHikariSpecificPropertiesIsSet() throws Exception {
EnvironmentTestUtils.addEnvironment(context,
"spring.datasource.type:" + HikariDataSource.class.getName(),
"spring.datasource.hikari.catalog:test_catalog");
context.register(DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
context.refresh();
DataSource dataSource = context.getBean(DataSource.class);
assertThat(dataSource).isNotNull();
assertThat(dataSource).isInstanceOf(DecoratedDataSource.class);
DataSource realDataSource = ((DecoratedDataSource) dataSource).getRealDataSource();
assertThat(realDataSource).isInstanceOf(HikariDataSource.class);
assertThat(((HikariDataSource) realDataSource).getCatalog()).isEqualTo("test_catalog");
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:17,代码来源:DataSourceDecoratorAutoConfigurationTests.java
示例5: testCustomDataSourceDecoratorApplied
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; //导入依赖的package包/类
@Test
public void testCustomDataSourceDecoratorApplied() throws Exception {
System.setProperty(PropertyLoader.PROPERTIES_FILE_PATH, "db/decorator/flexy-pool.properties");
context.register(TestDataSourceDecoratorConfiguration.class,
DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
context.refresh();
DataSource dataSource = context.getBean(DataSource.class);
assertThat(dataSource).isNotNull();
DataSource customDataSource = ((DecoratedDataSource) dataSource).getDecoratedDataSource();
assertThat(customDataSource).isInstanceOf(CustomDataSourceProxy.class);
DataSource realDataSource = ((DecoratedDataSource) dataSource).getRealDataSource();
assertThat(realDataSource).isInstanceOf(org.apache.tomcat.jdbc.pool.DataSource.class);
assertThatDataSourceDecoratingChain(dataSource).containsExactly(CustomDataSourceProxy.class, P6DataSource.class, ProxyDataSource.class, FlexyPoolDataSource.class);
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:21,代码来源:DataSourceDecoratorAutoConfigurationTests.java
示例6: testDecoratingCanBeDisabledForSpecificBeans
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; //导入依赖的package包/类
@Test
public void testDecoratingCanBeDisabledForSpecificBeans() throws Exception {
EnvironmentTestUtils.addEnvironment(context,
"decorator.datasource.exclude-beans:secondDataSource");
context.register(TestMultiDataSourceConfiguration.class,
DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
context.refresh();
DataSource dataSource = context.getBean("dataSource", DataSource.class);
assertThat(dataSource).isInstanceOf(DecoratedDataSource.class);
DataSource secondDataSource = context.getBean("secondDataSource", DataSource.class);
assertThat(secondDataSource).isInstanceOf(BasicDataSource.class);
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:17,代码来源:DataSourceDecoratorAutoConfigurationTests.java
示例7: testDecoratingHikariDataSourceWithDefaultStrategies
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; //导入依赖的package包/类
@Test
public void testDecoratingHikariDataSourceWithDefaultStrategies() throws Exception {
EnvironmentTestUtils.addEnvironment(context,
"spring.datasource.type:" + HikariDataSource.class.getName());
context.register(DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
context.refresh();
DataSource dataSource = context.getBean(DataSource.class);
assertDataSourceOfType(dataSource, HikariDataSource.class);
FlexyPoolDataSource<HikariDataSource> flexyPoolDataSource = assertDataSourceOfType(dataSource, HikariDataSource.class);
IncrementPoolOnTimeoutConnectionAcquiringStrategy strategy1 =
findStrategy(flexyPoolDataSource, IncrementPoolOnTimeoutConnectionAcquiringStrategy.class);
assertThat(strategy1).isNotNull();
assertThat(strategy1).hasFieldOrPropertyWithValue("maxOverflowPoolSize", 15);
assertThat(strategy1).hasFieldOrPropertyWithValue("timeoutMillis", 500);
RetryConnectionAcquiringStrategy strategy2 =
findStrategy(flexyPoolDataSource, RetryConnectionAcquiringStrategy.class);
assertThat(strategy2).isNotNull();
assertThat(strategy2).hasFieldOrPropertyWithValue("retryAttempts", 2);
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:24,代码来源:FlexyPoolConfigurationTests.java
示例8: testDecoratingHikariDataSourceWithCustomPropertyStrategies
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; //导入依赖的package包/类
@Test
public void testDecoratingHikariDataSourceWithCustomPropertyStrategies() throws Exception {
EnvironmentTestUtils.addEnvironment(context,
"spring.datasource.type:" + HikariDataSource.class.getName(),
"decorator.datasource.flexy-pool.acquiring-strategy.increment-pool.max-overflow-pool-size:15",
"decorator.datasource.flexy-pool.acquiring-strategy.increment-pool.timeout-millis:500",
"decorator.datasource.flexy-pool.acquiring-strategy.retry.attempts:5");
context.register(DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
HikariConfiguration.class);
context.refresh();
DataSource dataSource = context.getBean(DataSource.class);
FlexyPoolDataSource<HikariDataSource> flexyPoolDataSource = assertDataSourceOfType(dataSource, HikariDataSource.class);
IncrementPoolOnTimeoutConnectionAcquiringStrategy strategy1 =
findStrategy(flexyPoolDataSource, IncrementPoolOnTimeoutConnectionAcquiringStrategy.class);
assertThat(strategy1).isNotNull();
assertThat(strategy1).hasFieldOrPropertyWithValue("maxOverflowPoolSize", 35);
assertThat(strategy1).hasFieldOrPropertyWithValue("timeoutMillis", 10000);
RetryConnectionAcquiringStrategy strategy2 =
findStrategy(flexyPoolDataSource, RetryConnectionAcquiringStrategy.class);
assertThat(strategy2).isNotNull();
assertThat(strategy2).hasFieldOrPropertyWithValue("retryAttempts", 5);
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:27,代码来源:FlexyPoolConfigurationTests.java
示例9: testJpaCoexistsHappily
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; //导入依赖的package包/类
@Test
public void testJpaCoexistsHappily() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.url:jdbc:hsqldb:mem:testsecdb");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.initialize:false");
this.context.register(EntityConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class);
// This can fail if security @Conditionals force early instantiation of the
// HibernateJpaAutoConfiguration (e.g. the EntityManagerFactory is not found)
this.context.refresh();
assertThat(this.context.getBean(JpaTransactionManager.class)).isNotNull();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:SecurityAutoConfigurationTests.java
示例10: testDefaultDdlAutoForMySql
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; //导入依赖的package包/类
@Test
public void testDefaultDdlAutoForMySql() throws Exception {
// Set up environment so we get a MySQL database but don't require server to be
// running...
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.driverClassName:com.mysql.jdbc.Driver",
"spring.datasource.url:jdbc:mysql://localhost/nonexistent",
"spring.datasource.initialize:false", "spring.jpa.database:MYSQL");
this.context.register(TestConfiguration.class, DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
HibernateJpaAutoConfiguration.class);
this.context.refresh();
JpaProperties bean = this.context.getBean(JpaProperties.class);
DataSource dataSource = this.context.getBean(DataSource.class);
String actual = bean.getHibernateProperties(dataSource)
.get("hibernate.hbm2ddl.auto");
// Default is generic and safe
assertThat(actual).isNull();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:CustomHibernateJpaAutoConfigurationTests.java
示例11: processEngineWithJpaEntityManager
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; //导入依赖的package包/类
@Test
public void processEngineWithJpaEntityManager() throws Exception {
AnnotationConfigApplicationContext context = this.context(DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class, JpaProcessEngineAutoConfiguration.JpaConfiguration.class);
Assert.assertNotNull("entityManagerFactory should not be null", context.getBean(EntityManagerFactory.class));
Assert.assertNotNull("the processEngine should not be null!", context.getBean(ProcessEngine.class));
SpringProcessEngineConfiguration configuration = context.getBean(SpringProcessEngineConfiguration.class);
Assert.assertNotNull("the " + SpringProcessEngineConfiguration.class.getName() + " should not be null", configuration);
Assert.assertNotNull(configuration.getJpaEntityManagerFactory());
}
示例12: testJpaCoexistsHappily
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; //导入依赖的package包/类
@Test
public void testJpaCoexistsHappily() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.url:jdbc:hsqldb:mem:testsecdb");
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.initialize:false");
this.context.register(EntityConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class);
// This can fail if security @Conditionals force early instantiation of the
// HibernateJpaAutoConfiguration (e.g. the EntityManagerFactory is not found)
this.context.refresh();
assertNotNull(this.context.getBean(JpaTransactionManager.class));
}
示例13: testDefaultDdlAutoForMySql
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; //导入依赖的package包/类
@Test
public void testDefaultDdlAutoForMySql() throws Exception {
// Set up environment so we get a MySQL database but don't require server to be
// running...
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.driverClassName:com.mysql.jdbc.Driver",
"spring.datasource.url:jdbc:mysql://localhost/nonexistent",
"spring.datasource.initialize:false", "spring.jpa.database:MYSQL");
this.context.register(TestConfiguration.class, DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
HibernateJpaAutoConfiguration.class);
this.context.refresh();
JpaProperties bean = this.context.getBean(JpaProperties.class);
DataSource dataSource = this.context.getBean(DataSource.class);
String actual = bean.getHibernateProperties(dataSource)
.get("hibernate.hbm2ddl.auto");
// Default is generic and safe
assertThat(actual, nullValue());
}
示例14: testAddsP6SpyListener
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; //导入依赖的package包/类
@Test
public void testAddsP6SpyListener() {
context.setClassLoader(new HidePackagesClassLoader("com.vladmihalcea.flexypool", "net.ttddyy.dsproxy"));
context.register(DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
TraceAutoConfiguration.class,
SleuthLogAutoConfiguration.class,
SleuthListenerAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
context.refresh();
JdbcEventListenerFactory jdbcEventListenerFactory = context.getBean(JdbcEventListenerFactory.class);
CompoundJdbcEventListener jdbcEventListener = (CompoundJdbcEventListener) jdbcEventListenerFactory.createJdbcEventListener();
assertThat(jdbcEventListener.getEventListeners()).extracting("class").contains(TracingJdbcEventListener.class);
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:16,代码来源:SleuthListenerAutoConfigurationTests.java
示例15: testDoesNotAddP6SpyListenerIfNoTracer
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; //导入依赖的package包/类
@Test
public void testDoesNotAddP6SpyListenerIfNoTracer() {
context.setClassLoader(new HidePackagesClassLoader("com.vladmihalcea.flexypool", "net.ttddyy.dsproxy"));
context.register(DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
SleuthListenerAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
context.refresh();
JdbcEventListenerFactory jdbcEventListenerFactory = context.getBean(JdbcEventListenerFactory.class);
CompoundJdbcEventListener jdbcEventListener = (CompoundJdbcEventListener) jdbcEventListenerFactory.createJdbcEventListener();
assertThat(jdbcEventListener.getEventListeners()).extracting("class").doesNotContain(TracingJdbcEventListener.class);
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:14,代码来源:SleuthListenerAutoConfigurationTests.java