Skip to content

Spring Boot v3, Spring Security v6, JWT, Swagger, OpenAPI v3, Roles Based, JPA, Lombok, Validation, PostgreSQL

Notifications You must be signed in to change notification settings

wahyubudii/spring-boot-boilerplate

Repository files navigation

API Documentation from Swagger in your local

Open in browser http://localhost:<server-port>/swagger-ui/index.html
server port value by default is: 8080, but you can adjust in the /application.yml file

Dependency

– If you want to use PostgreSQL:

<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <scope>runtime</scope>
</dependency>

– or MySQL:

<dependency>
  <groupId>com.mysql</groupId>
  <artifactId>mysql-connector-j</artifactId>
  <scope>runtime</scope>
</dependency>

Configure Spring Datasource, JPA, App properties

Open src/main/resources/application.yml

  • For PostgreSQL:
spring:
  datasource:
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/dbname
    username: root
    password: root
  jpa:
    hibernate:
      ddl-auto: update # Hibernate ddl auto (create, create-drop, validate, update)
    show-sql: true
    database: postgresql
    database-platform: org.hibernate.dialect.PostgreSQLDialect
  security:
    jwt:
      secret: jwtSecretKey
      expiration: 86400000 # 24 hours
  • For MySQL
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/dbname
    username: root
    password: root
  jpa:
    hibernate:
      ddl-auto: update # Hibernate ddl auto (create, create-drop, validate, update)
    show-sql: true
  security:
    jwt:
      secret: jwtSecretKey
      expiration: 86400000 # 24 hours

Run following SQL insert statements

– multi data

INSERT INTO roles (id, name) VALUES 
(gen_random_uuid(), 'ROLE_ADMIN'),
(gen_random_uuid(), 'ROLE_USER'),
(gen_random_uuid(), 'ROLE_MODERATOR');

– single data

INSERT INTO roles (id, name) VALUES 
(gen_random_uuid(), 'ROLE_MODERATOR');

For more detail, please visit:

Secure Spring Boot with Spring Security & JWT Authentication

About

Spring Boot v3, Spring Security v6, JWT, Swagger, OpenAPI v3, Roles Based, JPA, Lombok, Validation, PostgreSQL

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages