Spring Test DBunit Warning

后端 未结 4 1810
迷失自我
迷失自我 2021-02-19 03:45

I am using spring-test-dbunit and I get a warning in my Unit tests with this message:

Code:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration         


        
4条回答
  •  失恋的感觉
    2021-02-19 04:05

    Just wanted to add the same solution as Java Config:

    @Bean
    public DataSource dataSource() {
        DataSource dataSource = ...
        return dataSource;
    }
    
    @Bean
    public DatabaseConfigBean dbUnitDatabaseConfig() {
        DatabaseConfigBean dbConfig = new com.github.springtestdbunit.bean.DatabaseConfigBean();
        dbConfig.setDatatypeFactory(new org.dbunit.ext.h2.H2DataTypeFactory());
        return dbConfig;
    }
    
    @Bean
    public DatabaseDataSourceConnectionFactoryBean dbUnitDatabaseConnection() {
        DatabaseDataSourceConnectionFactoryBean dbConnection = new com.github.springtestdbunit.bean.DatabaseDataSourceConnectionFactoryBean(dataSource());
        dbConnection.setDatabaseConfig(dbUnitDatabaseConfig());
        return dbConnection;
    }
    

提交回复
热议问题