當前位置: 首頁>>代碼示例>>Java>>正文


Java DataSourceAutoConfiguration類代碼示例

本文整理匯總了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());
}
 
開發者ID:flowable,項目名稱:flowable-engine,代碼行數:11,代碼來源:ProcessEngineAutoConfigurationTest.java

示例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));
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:18,代碼來源:SecurityAutoConfigurationTests.java

示例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());
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:20,代碼來源:CustomHibernateJpaAutoConfigurationTests.java

示例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


注:本文中的org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。