Spring Test DBUnit和表模式名称 [英] Spring Test DBUnit and table schema name

查看:535
本文介绍了Spring Test DBUnit和表模式名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring Test DBUnit中使用 @DatabaseSetup 注释时,是否可以设置表模式名称?目前我正在使用它:

Is it possible to set the table schema name when using @DatabaseSetup annotation from Spring Test DBUnit? Currently I'm using it like this:

@DatabaseSetup("user-data.xml")
public class UserMapperTest {
}

user-data.xml :(我也尝试设置元素名称为user.system_user,没有任何运气)

user-data.xml: (I also tried to set the element name to user.system_user without any luck)

<dataset>
    <system_user
        ...
        />
</dataset>

在这里,我正在使用名为user的模式创建我的表:

And here I'm creating my table with schema called user:

create table "user".system_user (...);

这是我在运行测试时得到的例外:

And this is the exception that I get when running test:

org.h2.jdbc.JdbcSQLException: Table "SYSTEM_USER" not found; SQL statement:
delete from SYSTEM_USER [42102-175]


推荐答案

我用过这个技巧。
首先,我们需要OracleConnection bean:

I used this trick. First, we need OracleConnection bean:

<bean id="oracleConnection" class="org.dbunit.ext.oracle.OracleConnection">
    <constructor-arg value="#{dataSource.getConnection()}"/>
    <constructor-arg value="<your_scheme_name>"/>
</bean>

然后你可以在你的方法中使用这个注释

Then you can use this annotation in your methods

@DbUnitConfiguration(databaseConnection = "oracleConnection")
@DatabaseSetup(...)

希望有所帮助。

这篇关于Spring Test DBUnit和表模式名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆