Embedded MariaDB4j Spring Boot Configuration
#Setting to blank will put db into a tmp directory and recreate every test run | |
mariaDB4j.dataDir= | |
#Pick a random open port | |
mariaDB4j.port=0 |
#Location of db files. delete this directory if you need to recreate from scratch | |
mariaDB4j.dataDir=./data/local | |
#Default is 3306, so using 3307 just in case it is already running on this machine | |
mariaDB4j.port=3307 | |
app.mariaDB4j.databaseName=app_alpha | |
spring.datasource.url=jdbc:mariadb://localhost:3307/ | |
spring.datasource.username=root | |
spring.datasource.password= | |
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver | |
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect |
import ch.vorburger.mariadb4j.DBConfigurationBuilder | |
import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService | |
import org.springframework.beans.factory.annotation.Value | |
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder | |
import org.springframework.context.annotation.Bean | |
import org.springframework.context.annotation.Configuration | |
import org.springframework.context.annotation.Profile | |
import javax.sql.DataSource | |
@Configuration | |
@Profile(['local', 'integrationTest']) | |
class EmbeddedMariaDbConfig { | |
@Bean | |
MariaDB4jSpringService mariaDB4jSpringService() { | |
new MariaDB4jSpringService() | |
} | |
@Bean | |
DataSource dataSource(MariaDB4jSpringService mariaDB4jSpringService, | |
@Value('${app.mariaDB4j.databaseName}') String databaseName, | |
@Value('${spring.datasource.username}') String datasourceUsername, | |
@Value('${spring.datasource.password}') String datasourcePassword, | |
@Value('${spring.datasource.driver-class-name}') String datasourceDriver) { | |
//Create our database with default root user and no password | |
mariaDB4jSpringService.getDB().createDB(databaseName) | |
DBConfigurationBuilder config = mariaDB4jSpringService.getConfiguration() | |
DataSourceBuilder | |
.create() | |
.username(datasourceUsername) | |
.password(datasourcePassword) | |
.url(config.getURL(databaseName)) | |
.driverClassName(datasourceDriver) | |
.build(); | |
} | |
} |
This comment has been minimized.
This comment has been minimized.
@vojtapol, since this is groovy, the last line is a returned without having the actual word return. And as long as mariaDB4j.dataDir= is left blank this code will recreate the storage everytime like H2. |
This comment has been minimized.
This comment has been minimized.
FYI to anyone coming here and receiving an error of |
This comment has been minimized.
This comment has been minimized.
nice catch, thanks @mrbusche! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
The
dataSource
bean method is missing areturn
.I would also like to see an example of how automatically wiping the MariaDB4 storage after test to mimic H2.