Use MySQL in a Development Environment

Introduction

Goal

Set up your local Bloomreach Experience Manager development environment to use a MySQL database for storage.

This page describes how to configure a project that relies on Cargo to run Tomcat and MySQL directly on the development host. Using a Docker-based configuration requires significantly less setup work, whether you intend to run MySQL within a container or directly on the host. See Run and Develop with Docker.

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>
Make sure this dependency is in the /project/dependencies section, not to be confused with the  /project/depencencyManagement/dependencies/ section!

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>     
In the configuration snippet above some non-relevant configuration has been left out for clarity.

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>
In the configuration snippet above some non-relevant configuration has been left out for clarity.

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.

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?