Skip to content

Setup Your Project

Sahil Kharya edited this page May 27, 2020 · 3 revisions

Setting up your DataBase

  • You need to install Docker as we will be using a docker image of MariaDB Database.

Setting up your docker image

To setup your database using the mariaDB image from docker. Run this command:

docker run --name db_Name -p 3306:3306 -v {THE_PATH_TO_STORE_DATA}:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=password -d mariadb:latest

This will create a docker container image on your system which you can use to connect with your database. The database server is running on Port #3306 as defined in the docker run command.

Now, every time you want to start your database server, run docker command

$ docker start db_Name

And your Server is ready to use


Building your Maven Project on Spring

  • In the Spring Tool Suite, you can either use our project by cloning it or create a new Maven Project.
  • All your java program will be inside the package /src/main/java
  • To connect your database (mariaDB image) to your spring application:
  1. Make a new file named application.properties inside the package /src/main/resources
  2. In this file, add the following code:

spring.jpa.hibernate.ddl-auto=update spring.datasource.driver-class-name=org.mariadb.jdbc.Driver

spring.datasource.username=root

spring.datasource.url=jdbc:mariadb://127.0.0.1:3306/{YOUR_DATABASE_NAME}

spring.datasource.password={password}

spring.jpa.show-sql=true

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDB103Dialect

Clone this wiki locally