I want to create an in-memory database populated with test data for fast testing, so I declare this bean in my configuration file, but I also want so set this properties:
MODE=MySQL
DB_CLOSE_ON_EXIT=FALSE
but I don't know where to do it
@Bean
public DataSource dataSource(){
return
(new EmbeddedDatabaseBuilder())
.setType(EmbeddedDatabaseType.H2) //.H2
.addScript("classpath:db/H2.schema.sql")
.addScript("classpath:db/H2.data.sql")
.build();
}
try this
@Bean
public DataSource dataSource(){
return
new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.setName("testDB;DB_CLOSE_ON_EXIT=FALSE;MODE=MySQL")
.addScript("classpath:db/H2.schema.sql")
.addScript("classpath:db/H2.data.sql")
.build();
}
You can try using EmbeddedDatabaseBuilder.setName()
@Bean
public DataSource dataSource() {
return
new EmbeddedDatabaseBuilder()
.setName("testdb;MODE=MySQL;DB_CLOSE_ON_EXIT=false")
.setType(EmbeddedDatabaseType.H2) //.H2
.addScript("classpath:db/H2.schema.sql")
.addScript("classpath:db/H2.data.sql")
.build();
}
Note: I have not tried this myself, but found a clue on this answer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With