Search in sources :

Example 21 with BasicDataSource

use of org.apache.commons.dbcp2.BasicDataSource in project spring-boot by spring-projects.

the class SimpleTwoDataSourcesExampleTests method validateConfiguration.

@Test
public void validateConfiguration() throws SQLException {
    assertThat(this.context.getBeansOfType(DataSource.class)).hasSize(2);
    DataSource dataSource = this.context.getBean(DataSource.class);
    assertThat(this.context.getBean("fooDataSource")).isSameAs(dataSource);
    assertThat(dataSource.getConnection().getMetaData().getURL()).startsWith("jdbc:h2:mem:");
    BasicDataSource barDataSource = this.context.getBean("barDataSource", BasicDataSource.class);
    assertThat(barDataSource.getUrl()).isEqualTo("jdbc:h2:mem:bar;DB_CLOSE_DELAY=-1");
    assertThat(barDataSource.getMaxTotal()).isEqualTo(42);
}
Also used : BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) DataSource(javax.sql.DataSource) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 22 with BasicDataSource

use of org.apache.commons.dbcp2.BasicDataSource in project Axe by DongyuCai.

the class DbcpDataSourceFactory method init.

private void init() {
    try {
        DATA_SOURCE = new BasicDataSource();
        DATA_SOURCE.setDriverClassName(DRIVER);
        DATA_SOURCE.setUrl(URL);
        DATA_SOURCE.setUsername(USERNAME);
        DATA_SOURCE.setPassword(PASSWORD);
    } catch (Exception e) {
        LOGGER.error("jdbc driver : " + DRIVER);
        LOGGER.error("jdbc url : " + URL);
        LOGGER.error("jdbc username : " + USERNAME);
        LOGGER.error("jdbc password : " + PASSWORD);
        LOGGER.error("load jdbc driver failure", e);
    }
}
Also used : BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) SQLException(java.sql.SQLException)

Aggregations

BasicDataSource (org.apache.commons.dbcp2.BasicDataSource)22 Test (org.junit.Test)11 DataSource (javax.sql.DataSource)4 SQLException (java.sql.SQLException)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 DataSourceMonitorAccessor (com.navercorp.pinpoint.plugin.commons.dbcp2.DataSourceMonitorAccessor)1 Dbcp2DataSourceMonitor (com.navercorp.pinpoint.plugin.commons.dbcp2.Dbcp2DataSourceMonitor)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 URL (java.net.URL)1 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 InitialContext (javax.naming.InitialContext)1 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)1 URLResource (org.apache.cayenne.resource.URLResource)1 ManagedConnection (org.apache.commons.dbcp2.managed.ManagedConnection)1 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)1