Last active
April 26, 2021 12:31
-
-
Save jeffsheets/780819e09654077db4fe4087f378e78d to your computer and use it in GitHub Desktop.
Embedded MariaDB4j Spring Boot Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 my dependency::
org.mariadb.jdbc mariadb-java-client 2.3.0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What version of vorburger mariaDB4j need to be used . I am trying the same but its not working for me . Version of mariadb4j used by me is 2.2.3.
Looking for some help !!
@itDarashukD