Tim*_*Tim 18 java dbunit warnings
我在最新版本2.4.8中使用DbUnit,我在单元测试中收到许多警告:
WARN : org.dbunit.dataset.AbstractTableMetaData -
Potential problem found: The configured data type factory
'class org.dbunit.dataset.datatype.DefaultDataTypeFactory'
might cause problems with the current database 'MySQL' (e.g. some datatypes may
not be supported properly). In rare cases you might see this message because the
list of supported database products is incomplete (list=[derby]). If so please
request a java-class update via the forums.If you are using your own
IDataTypeFactory extending DefaultDataTypeFactory, ensure that you override
getValidDbProducts() to specify the supported database products.
Run Code Online (Sandbox Code Playgroud)
所以我想我添加了这个(我使用MySQL数据库):
protected void setUpDatabaseConfig(DatabaseConfig config) {
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory());
}
Run Code Online (Sandbox Code Playgroud)
但这无助于避免这些警告.这有什么不对?
提前谢谢你和最好的问候蒂姆.
rea*_*ler 30
我用dbunit faq中的信息解决了这个问题.只是设置数据类型工厂属性使警告消失.
Connection dbConn = template.getDataSource().getConnection();
IDatabaseConnection connection = new DatabaseConnection(dbConn, "UTEST", false);
DatabaseConfig dbConfig = connection.getConfig();
// added this line to get rid of the warning
dbConfig.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new OracleDataTypeFactory());
Run Code Online (Sandbox Code Playgroud)
使用Spring-Boot,您可以使用此类配置bean
@Configuration
public class DbUnitConfiguration {
@Autowired
private DataSource dataSource;
@Bean
public DatabaseDataSourceConnectionFactoryBean dbUnitDatabaseConnection() {
DatabaseConfigBean bean = new DatabaseConfigBean();
bean.setDatatypeFactory(new MySqlDataTypeFactory());
DatabaseDataSourceConnectionFactoryBean dbConnectionFactory = new DatabaseDataSourceConnectionFactoryBean(dataSource);
dbConnectionFactory.setDatabaseConfig(bean);
return dbConnectionFactory;
}
}
Run Code Online (Sandbox Code Playgroud)