Skip to content

Instantly share code, notes, and snippets.

@fsans
Last active January 8, 2021 14:18
Show Gist options
  • Save fsans/0239f256f9e74b57026a44ab9860e2ed to your computer and use it in GitHub Desktop.
Save fsans/0239f256f9e74b57026a44ab9860e2ed to your computer and use it in GitHub Desktop.

Spring Boot app with REST API demo, using the following frameworks:

  • Java 8
  • SpringBoot
  • JPA & Hibernate
  • H2 & MySQL
  • Maven

1 Create a new Spring Boot starter app

1.1 Using springboot CLI:
spring init -n=demo -d=web,jpa,mysql,devtools --package-name=com.fmcat demo

the project is generated in ./demo folder

1.2 Using spring.io starter utility:

Go to http://start.spring.io

  • set package to: com.fmcat
  • set name to: demo
  • add dependencies: web jpa mysql devtools
  • generate project (...the project is downloaded)
  • open terminal and go to the generated folder (unzip downloaded file)

the project is doenloaded as zip file. Unzip and go into the folder

2 Create a new database

Not required if using H2.

For other SQL engines create a new database using your IDE of choice, with :

name: mydatabase
user: *****
pwd: ******

3 Setup application properties

Edit src/main/resources/application.properties Add database details and hibernate preferences

    spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase?useSSL=false
    spring.datasource.username=*******
    spring.datasource.password=*******
    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
    spring.jpa.hibernate.ddl-auto = update
    logging.level.org.hibernate.SQL=DEBUG
    logging.level.org.hibernate.type=TRACE

4 Create entities

Options:

4.1 Reverse engineering from Database Tables
4.2 Reverse engineering from java Entities

5

6

7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment