Skip to content

DemisR/spring-boot-postgres-sample

 
 

Repository files navigation

Welcome to spring-boot-postgres Sample project

Simple SpringBoot application using a database and provide a basic API.

Pre requisites

  • Java 11
  • PostgreSQL database (H2 database for development profile)

Application Configuration

One way to configure Spring applications is to use YAML configuration files. Springboot, loads the application properties outside of your packaged jar from the application.yml file.

Following is a simple YAML file that contains configuration for use PostgreSQL database datasource.

info:
  app:
    name: springusers
    description: "springuser demo app"
    version: 2.0.0

spring:
  application:
    name: springusers
  datasource:
    url: jdbc:postgresql://database:5432/sampledb
    username: sampleuser
    password: sampleuserpassword
    platform: POSTGRESQL
  jpa:
    hibernate:
      ddl-auto: create-drop
    show-sql: true
server:
  port: 8080

management:
  endpoint:
    health:
      show-details: always
      sensitive: false
  endpoints:
    web:
      exposure:
        include: prometheus, info, health, env
  security:
    enabled: false
  metrics:
    tags:
      application: ${spring.application.name}
  info:
    env:
      enabled: true

For the development mode the dev profile load the properties from src/main/resources/config/dev/application-dev.yml.

Application Usage

To add a user make a POST like this example : http://localhost:8080/user/john.doe

To list all users : http://localhost:8080/user

Others useful endpoints:

  • /actuator/info
  • /actuator/health
  • /actuator/env
  • /actuator/prometheus

Developpement instructions

Run Application Locally

mvn -Dspring.profiles.active={dev-prod} spring-boot:run

Run Integration Tests

mvn test

Build

mvn package

About

Spring-boot sample project

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • Java 86.4%
  • Dockerfile 9.4%
  • Shell 2.5%
  • HTML 1.7%