Skip to content

A Spring Boot Scaffold contains necessary components: JPA, Test, Hibernate, Database connector, Swagger, MapStruct etc.

License

Notifications You must be signed in to change notification settings

hirelala/SpringBootScaffold

Repository files navigation

SpringBootScaffold

SpringBootScaffold is a scaffold for Spring Boot project. It contains basic configurations and common used components.

  • Spring Boot: 3.1.0
    • Spring JPA
    • Spring Web
    • Thymeleaf
    • Validation
    • Spring Test
  • Database Connector:
    • H2 Database: 2.2.224
    • MySQL Connector: 8.2.0
    • PostgreSQL: 42.7.1
  • Spring Doc (Swagger): 2.3.0
  • Lombok: 1.18.30
  • Mapstruct: 1.5.5.Final

1 Run in IDEA IDE

Click to expand
  1. Make sure your IDEA IDE setting to JDK 17.
  2. Run MainApplication.java to start the server.
  3. Open http://localhost:8080/swagger-ui/index.html to see the swagger doc.
  4. The data will save to H2 database file ./springboot_scaffold.mv.db by default.

2 Database configuration

Click to expand

SpringBootScaffold uses H2 memory database default. It can be changed easily to other database by specifying environment variables or application.yml.

Following shows how to change by environment variables.

2.1 H2 database (default)

H2 is DEFAULT database for SpringBootScaffold. Its configuration is:

DB_JDBC_URL=jdbc:h2:mem:springboot_scaffold
DB_USERNAME=sa
DB_PASSWORD=password
DB_DRIVER_CLASS=org.h2.Driver
DB_JPA_DIALECT=org.hibernate.dialect.H2Dialect

Once Spring Boot started, H2 can be access by http://localhost:8080/h2-console.

2.2 MySQL

Create a MySQL database named springboot_scaffold, then setup environment variables as following (change accordingly):

DB_JDBC_URL=jdbc:mysql://localhost:3306/springboot_scaffold?useUnicode=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=GMT%2B8
DB_USERNAME=root
DB_PASSWORD=12345678
DB_DRIVER_CLASS=com.mysql.cj.jdbc.Driver
DB_JPA_DIALECT=org.hibernate.dialect.MySQLDialect

2.3 PostgreSQL

Create a PostgreSQL database named springboot_scaffold, then setup environment variables as following (change accordingly):

DB_JDBC_URL=jdbc:postgresql://localhost:5432/springboot_scaffold
DB_USERNAME=postgres
DB_PASSWORD=12345678
DB_DRIVER_CLASS=org.postgresql.Driver
DB_JPA_DIALECT=org.hibernate.dialect.PostgreSQLDialect

3 How to Build Jar

Click to expand
java --version  # make sure your java version is 17
./gradlew clean build
java -jar build/libs/SpringbootScaffold.jar

4 One Click Deployment

Deploy to Render (free)

Deploy to DigitalOcean

amplifybutton (AWS)