[英]Run a SQL script in spring-test root startup
I have a spring project, and I am doing unit testing of my project with spring-test in a PostgreSQL database for the test (I have a database for test and another for development). 我有一个春季项目,并且正在使用PostgreSQL数据库中的spring-test对项目进行单元测试(我有一个用于测试的数据库,另一个用于开发的数据库)。 And I want to initialize my database with a SQL script in the startup (root) of all tests.
我想在所有测试的启动(根)中使用SQL脚本初始化数据库。
I need some direction, I found "flyway" but first I am looking for something with basic spring or something like that or any idea. 我需要一些指导,我找到了“飞路”,但首先,我正在寻找基本弹簧之类的东西或类似的东西或任何想法。 Thanks
谢谢
To initialize an existing (ie, normally _external) database when the Spring ApplicationContext
starts, you can either use the jbbc
namespace in XML or a DataSourceInitializer
with JavaConfig. 要在Spring
ApplicationContext
启动时初始化现有数据库(即通常为_external),可以在XML中使用jbbc
命名空间,也可以在JavaConfig中使用DataSourceInitializer
。
See Initializing a database using Spring XML and DataSourceInitializer for details. 有关详细信息,请参见使用Spring XML和DataSourceInitializer 初始化数据库 。
there is simple implementation from spring side all we need is just add line below 从弹簧端有一个简单的实现,我们需要的只是在下面添加行
ScriptUtils.executeSqlScript(connection, new ClassPathResource("DB_structures_Creation.sql"));
ScriptUtils.executeSqlScript(connection,new ClassPathResource(“ DB_structures_Creation.sql”)));
This implementation by default will uses H2 and will create all the tables and other stuff except pl-sql ones 默认情况下,此实现将使用H2,并将创建除pl-sql之外的所有表和其他内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.