{"id":22492587,"url":"https://github.com/garystafford/spring-postgresql-demo","last_synced_at":"2025-08-03T00:31:30.743Z","repository":{"id":54463444,"uuid":"126249072","full_name":"garystafford/spring-postgresql-demo","owner":"garystafford","description":"Spring Boot 2.0 application, backed by PostgreSQL, and designed for deployment to Pivotal Cloud Foundry (PCF)","archived":false,"fork":false,"pushed_at":"2018-05-21T02:25:11.000Z","size":83638,"stargazers_count":30,"open_issues_count":0,"forks_count":23,"subscribers_count":5,"default_branch":"master","last_synced_at":"2023-08-05T02:22:56.935Z","etag":null,"topics":["pcf","pivotal-cloud-foundry","postresql","spring","spring-boot"],"latest_commit_sha":null,"homepage":"https://wp.me/p1RD28-5Jh","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/garystafford.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-21T22:41:00.000Z","updated_at":"2023-07-20T12:58:43.000Z","dependencies_parsed_at":"2022-08-13T16:20:53.133Z","dependency_job_id":null,"html_url":"https://github.com/garystafford/spring-postgresql-demo","commit_stats":null,"previous_names":[],"tags_count":7,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garystafford%2Fspring-postgresql-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garystafford%2Fspring-postgresql-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garystafford%2Fspring-postgresql-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/garystafford%2Fspring-postgresql-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/garystafford","download_url":"https://codeload.github.com/garystafford/spring-postgresql-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228508010,"owners_count":17931264,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pcf","pivotal-cloud-foundry","postresql","spring","spring-boot"],"created_at":"2024-12-06T18:19:09.235Z","updated_at":"2024-12-06T18:19:11.740Z","avatar_url":"https://github.com/garystafford.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)   [![Build Status](https://travis-ci.org/garystafford/spring-postgresql-demo.svg?branch=master)](https://travis-ci.org/garystafford/spring-postgresql-demo)\n\n# Spring Boot 2.0 PostgreSQL Application Demonstration\n\nThis project was originally used for the Programmatic Ponderings blog post, [Developing Cloud-Native Data-Centric Spring Boot Applications for Pivotal Cloud Foundry](https://wp.me/p1RD28-5Jh), published March, 2018. Spring Boot 2.0 application, backed by PostgreSQL, and designed for deployment to Pivotal Cloud Foundry (PCF). Database changes are handled by Liquibase.\n\nAlso, this project was used for the two-part Programmatic Ponderings post, [Managing Applications Across Multiple Kubernetes Environments with Istio](https://wp.me/p1RD28-5L7), published April, 2018.\n\n## Docker Quick Start\n\nThe project now contains `Dockerfile` and `docker-compose.yml` files. If you have Docker and Docker Compose installed locally, you can preview project by creating Docker containers for both the PostgreSQL database and the Spring Boot application. To do so, execute the follow command from the root of the project\n\n```bash\ngit clone --depth 1 --branch master \\\n  https://github.com/garystafford/spring-postgresql-demo.git\ncd spring-postgresql-demo\n\ndocker-compose -p springdemo up -d\n```\n\nTo follow the startup of the Spring Boot application, use the `docker logs springdemo --follow` command. When complete, browse to `http://localhost:8080`. See the list of available resources below.\n\nTo delete both Docker containers when done previewing, use the `docker rm -f postgres springdemo` command.\n\n## Build and Run Application with Gradle\n\nThe project assumes you have Docker and the Cloud Foundry Command Line Interface (cf CLI) installed locally.\n\nFirst, provision the local PostgreSQL development database using Docker:\n\n```bash\n# create container\ndocker run --name postgres \\\n  -e POSTGRES_USERNAME=postgres \\\n  -e POSTGRES_PASSWORD=postgres1234 \\\n  -e POSTGRES_DB=elections \\\n  -p 5432:5432 \\\n  -d postgres\n\n# view container\ndocker container ls\n\n# trail container logs\ndocker logs postgres  --follow\n```\n\nLocal database connection details are set in the `src\\main\\resources\\application.yml` file.\n\nThe `default` Spring Profile, uses an [h2](http://www.h2database.com/) instance:\n\n```yaml\ndatasource:\n  url: jdbc:h2:mem:elections\n  username: sa\n  password:\n  driver-class-name: org.h2.Driver\n  jpa:\n    show-sql: true\nh2:\n  console:\n    enabled: true\n```\n\nThe `dev` Spring Profile, uses localhost PostgreSQL instance:\n\n```yaml\ndatasource:\n  url: jdbc:postgresql://localhost:5432/elections\n  username: postgres\n  password: postgres1234\n  driver-class-name: org.postgresql.Driver\njpa:\n  show-sql: true\n```\n\nOptionally, you can override any of the setting in the `src\\main\\resources\\application.yml` files, by setting local environment variables, such as:\n\n```bash\n# use 'set' on Windows\nexport SPRING_PROFILES_ACTIVE=\u003cprofile\u003e\nexport SPRING_DATASOURCE_URL=\u003csome_other_url\u003e\nexport SPRING_DATASOURCE_USERNAME=\u003csome_other_username\u003e\nexport SPRING_DATASOURCE_PASSWORD=\u003csome_other_password\u003e\n```\n\nNext, build and run service locally, using Gradle, against the local Docker PostgreSQL database instance. This command will also execute the Liquibase change sets on the Docker PostgreSQL `elections` database.\n\n```bash\nSPRING_PROFILES_ACTIVE=dev ./gradlew clean bootRun\n```\n\nTo view Liquibase database changelog:\n\n```postgresplsql\nSELECT * FROM databasechangelog;\n```\n\nTo delete the local Docker-based PostgreSQL database:\n\n```bash\ndocker rm -f postgres\n```\n\n## Deploy to Pivotal Web Services\n\nPurchase and provision an ElephantSQL PostgreSQL as a Service instance through the Pivotal Services Marketplace. Note the 'panda' service plan is NOT FREE! To purchase, you must have a Pivotal account with a credit card attached.\n\n```bash\n# view elephantsql service plans\ncf marketplace -s elephantsql\n\n# purchase elephantsql service plan\ncf create-service elephantsql panda elections\n\n# display details of running service\ncf service elections\n```\n\nDeploy the Spring Boot service to Pivotal Web Services.\n\n```bash\ngradle build \u0026\u0026 cf push\n```\n\nScale up instances:\n\n```bash\n# scale up to 2 instances\ncf scale cf-spring -i 2\n\n# review status of both instances\ncf app pcf-postgresql-demo\n```\n\n## Available Resources\n\nBelow is a partial list of the application's exposed resources. To see all resources, use the `/actuator/mappings` resource.\n\n-   Actuator\n\n    -   `/`\n    -   `/actuator/mappings` (shows all resources!)\n    -   `/actuator/metrics`\n    -   `/actuator/metrics/{metric}`\n    -   `/actuator/liquibase`\n    -   `/actuator/env`\n    -   `/actuator/configprops`\n    -   `/actuator/health`\n    -   `/actuator/info`\n    -   `/actuator/beans`\n\n-   Swagger\n\n    -   `/swagger-ui.html`\n    -   `/v2/api-docs`\n\n-   h2 (`default` Spring Profile only)\n\n    -   `/h2-console`\n\n-   Candidates (DB Table)\n\n    -   `/candidates`\n    -   `/candidates/{id}`\n    -   `/profile/candidates`\n    -   `/candidates/search`\n    -   `/candidates/search/findByLastName?lastName=Obama`\n    -   `/candidates/search/findByPoliticalParty?politicalParty=Democratic%20Party`\n    -   `/candidates/summary`\n    -   `/candidates/summary/{politicalParty}`\n\n-   Elections (DB Table)\n\n    -   `/elections`\n    -   `/elections/{id}`\n    -   `/profile/elections`\n    -   `/elections/search`\n    -   `/elections/search/findByTitle?title=2012%20Presidential%20Election`\n    -   `/elections/search/findByDescriptionContains?description=American`\n    -   `/elections/summary`\n\n\n-   Votes (DB Table)\n\n    -   `/votes`\n    -   `/votes/{is}`\n    -   `/votes?page={page}}\u0026size={size}`\n    -   `/profile/votes`\n\n-   Election Candidates (DB Table)\n\n    -   `/electionCandidates`\n    -   `/profile/electionCandidates`\n\n-   Candidates, by Elections (DB View)\n\n    -   `/election-candidates` (GET only)\n    -   `/profile/election-candidates`\n    -   `/election-candidates/search/findByElection?election=2016%20Presidential%20Election`\n\n-   Individual Votes, by Election (DB View)\n\n    -   `/election-votes` (GET only)\n    -   `/election-votes?page={page}}\u0026size={size}` (GET only)\n    -   `/profile/election-votes`\n    -   `/election-votes/search/findByElection?election=2012%20Presidential%20Election`\n    -   `/election-votes/summary`\n    -   `/election-votes/summary/{election}`\n\n-   Total Votes by Election and by Candidate (DB View)\n\n    -   `/vote-totals` (GET only)\n    -   `/profile/vote-totals`\n    -   `/vote-totals/search/findByElection?election=2012%20Presidential%20Election`\n    -   `/election-votes/summary`\n\n## References\n\n-   \u003chttps://auth0.com/blog/integrating-spring-data-jpa-postgresql-liquibase\u003e\n-   \u003chttp://mrbool.com/rest-server-with-spring-data-spring-boot-and-postgresql/34023\u003e\n-   \u003chttps://www.tutorialspoint.com/postgresql/postgresql_create_database.htm\u003e\n-   \u003chttp://www.vogella.com/tutorials/Lombok/article.html\u003e\n-   \u003chttps://spring.io/guides/gs/accessing-data-jpa\u003e\n-   \u003chttps://dzone.com/articles/integrating-spring-data-jpa-postgresql-and-liquiba\u003e\n-   \u003chttps://www.javabullets.com/calling-database-views-from-spring-data-jpa\u003e\n-   \u003chttp://www.baeldung.com/swagger-2-documentation-for-spring-rest-api\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarystafford%2Fspring-postgresql-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgarystafford%2Fspring-postgresql-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgarystafford%2Fspring-postgresql-demo/lists"}