Use MySQL in a Development Environment
Introduction
Goal
Set up your local Bloomreach Experience Manager development environment to use a MySQL database for storage.
Background
By default a project created from the Maven archetype is set up to use an embedded H2 database for storage. In some use cases you may want to use a different database, such as MySQL, during development. For production environments this is described at Configuring Bloomreach Experience Manager for MySQL. This page describes the additional steps required in a Cargo-based local development environment.
Prerequisites
This page assumes that your Hippo project and local development environment are set up following the Getting Started tutorial.
It also assumes that you have installed MySQL and created a database and a user with sufficient privileges (see Configuring Bloomreach Experience Manager for MySQL).
Add the MySQL Driver as a Dependency to Your POM
In the project's root pom.xml add the following dependency:
<dependencies> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <version>8.0.33</version> <scope>provided</scope> </dependency> </dependencies>
Put the MySQL driver on the Cargo classpath
In the project's root pom.xml, locate the Cargo plugin configuration (in the cargo.run profile) and add the MySQL driver as a dependency to the container:
<plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven3-plugin</artifactId> <configuration> <container> <dependencies> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <classpath>extra</classpath> </dependency> </dependencies> </container> </configuration> </plugin>
Register a MySQL DataSource with Tomcat
Add a Resource declaration to conf/context.xml. Use the example provided at Configuring Bloomreach Experience Manager for MySQL and subtitute your database details. For local development without SSL validation add useSSL=false to the datasource url.
Create Custom Repository.xml
Add a file conf/repository.xml. Use the example provided at Configuring Bloomreach Experience Manager for MySQL.
Make the Repository Use the Custom Repository.xml
In the project's root pom.xml, locate the Cargo plugin configuration (in the cargo.run profile) and add the repo.config system property to system properties section of the container configuration:
<plugin> <groupId>org.codehaus.cargo</groupId> <artifactId>cargo-maven3-plugin</artifactId> <configuration> <container> <systemProperties> <repo.config>file:${project.basedir}/conf/repository.xml</repo.config> </systemProperties> </container> </configuration> </plugin>
Build and Run
Build and run your project as usual.
At the first startup the CMS webapp will create all required tables in the database.