{"id":17028400,"url":"https://github.com/gazbert/spring-boot-mongodb-app","last_synced_at":"2026-04-14T19:32:40.622Z","repository":{"id":53279938,"uuid":"256746854","full_name":"gazbert/spring-boot-mongodb-app","owner":"gazbert","description":"A Spring Boot sample app that uses MongoDB and shows how to test it.","archived":false,"fork":false,"pushed_at":"2021-03-31T21:56:27.000Z","size":204,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T19:47:28.083Z","etag":null,"topics":["checkstyle","gradle","jacoco","java","maven","mongodb","sample-app","spotbugs","spring-boot","spring-data-mongodb","testcontainers"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gazbert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-18T12:21:13.000Z","updated_at":"2020-04-21T19:38:11.000Z","dependencies_parsed_at":"2022-08-28T15:50:49.407Z","dependency_job_id":null,"html_url":"https://github.com/gazbert/spring-boot-mongodb-app","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gazbert/spring-boot-mongodb-app","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gazbert%2Fspring-boot-mongodb-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gazbert%2Fspring-boot-mongodb-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gazbert%2Fspring-boot-mongodb-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gazbert%2Fspring-boot-mongodb-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gazbert","download_url":"https://codeload.github.com/gazbert/spring-boot-mongodb-app/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gazbert%2Fspring-boot-mongodb-app/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31812968,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T18:05:02.291Z","status":"ssl_error","status_checked_at":"2026-04-14T18:05:01.765Z","response_time":153,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["checkstyle","gradle","jacoco","java","maven","mongodb","sample-app","spotbugs","spring-boot","spring-data-mongodb","testcontainers"],"created_at":"2024-10-14T07:54:05.367Z","updated_at":"2026-04-14T19:32:40.607Z","avatar_url":"https://github.com/gazbert.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spring Boot MongoDB App\n\n[![Build Status](https://travis-ci.org/gazbert/spring-boot-mongodb-app.svg?branch=master)](https://travis-ci.org/gazbert/spring-boot-mongodb-app)\n[![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=gazbert_spring-boot-mongodb-app\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=gazbert_spring-boot-mongodb-app)\n\n## What is this?\nA [Spring Boot](http://projects.spring.io/spring-boot/) sample app that integrates \n[MongoDB](https://www.mongodb.com/) using [Spring Data MongoDB](https://spring.io/projects/spring-data-mongodb).\n\nIt could be used as boilerplate for developing microservices that require a persistent document store.\n\nMongoDB is a NoSQL document database. It stores data in JSON-like documents. Spring Data provides\na model and repository layer for integrating with MongoDB.\n\n## Install MongoDB\nThe fastest way to get up and running is to use the [Docker image](https://hub.docker.com/_/mongo):\n\n```bash\ndocker pull mongo;\ndocker run -d -p 27017-27019:27017-27019 --name my-mongodb mongo:latest\n\n```\n\nOnce it's up and running, you can attach to it to run MongoDB commands: \n```bash\ndocker exec -it my-mongodb bash\n```\n\nLaunch the [Mongo Shell](https://docs.mongodb.com/manual/reference/mongo-shell/) client:\n```bash\nmongo\n```\n\nCheck it's working ok, e.g. list the dbs:\n```bash\nshow dbs\n```\n\nThe alternative is to install it natively as per the [official guide](https://docs.mongodb.com/manual/installation/).\n\n## Build Guide\nYou'll need JDK 11 installed on your dev box.\n\nYou can use [Gradle](https://gradle.org/) or [Maven](https://maven.apache.org) to build the app.\n\nBoth [Gradle Wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html) and \n[Maven Wrapper](https://github.com/takari/maven-wrapper) are included in the project.\n\n### Gradle\n1. From the project root, run `./gradlew build`\n1. To generate the Javadoc, run `./gradlew javadoc` and look in the `./build/docs/javadoc` folder.\n\n### Maven\n1. From the project root, run `./mvnw clean install`\n1. Take a look at the Javadoc in the `./target/apidocs` folders after the build completes.\n\n### Checkstyle\nThe app uses the [Google Style Guide](https://google.github.io/styleguide/javaguide.html)\nwhich is enforced during both the Gradle and Maven build - see the [build.gradle](./build.gradle) \nand [pom.xml](./pom.xml) files respectively. The Checkstyle report locations are:\n\n* Gradle - `./build/reports/checkstyle/main.html`\n* Maven - `./target/checkstyle-result.xml`\n\n### Code Coverage\nCode coverage is provided by [JaCoCo](https://www.eclemma.org/jacoco/) and is enforced at build time.\nIt's currently set to 80% line coverage. See the build files. The coverage report locations are:\n\n* Gradle - `./build/report/jacoco/test/html/index.html`\n* Maven - `./target/jacoco-report/index.html`\n\n### Code Quality\n[SpotBugs](https://spotbugs.github.io/) is run at build time. Any bugs found will fail the build. \nThe bug report locations are:\n\n* Gradle - `./build/report/jacoco/test/html/index.html`\n* Maven - `./target/spotbugsXml.xml`\n\n### Tests\nUnit tests are run as part of both Gradle and Maven builds.\n\n[JUnit](https://junit.org/junit4/), [Spring Boot Test](https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/reference/html/boot-features-testing.html)\n, and [Flapdoodle's](https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo) embedded MongoDB\nis used to unit test the code.\n\nYou'll need to stop any other instance of MongoDB that you have running, otherwise the tests will \nfail to due to port clashes.\n\nThe unit test report locations are:\n* Gradle - `build/reports/tests/test/index.html`\n* Maven - `./target/surefire-reports`\n\nThe integration tests require a running instance of MongoDB -\n[Testcontainers](https://www.testcontainers.org/) is used to achieve this. Don't forget to stop any\nother instances of MongoDB you have running before running the tests.\n\nThe IT tests are located [here](./src/integration-test/java/com/gazbert/mongosample/it).\n \nTo run the IT tests:\n* Gradle - `./gradlew integrationTests`\n* Maven  `./mvnw clean install -Pint`\n\nThe IT report locations are:\n* Gradle - `./build/reports/tests/integrationTests/index.html`\n* Maven - `./target/failsafe-reports`\n \n## Configuration\nThe configuration is held in the [./config/application.properties](./config/application.properties) \nfile.\n\nYou'll need to change the MongoDB connection details of you are running the database on a different\nmachine:\n\n```properties\nspring.data.mongodb.host=localhost\nspring.data.mongodb.port=27017\nspring.data.mongodb.database=sample-app\n```\n\nMongoDB authentication is not enabled for this demo - see the\n[MongoDB Manual](https://docs.mongodb.com/manual/tutorial/enable-authentication/) and the\n[Spring Data Docs](https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongo.mongo-db-factory-java)\nif you need to enable it.\n\n## User Guide\n\n### Running the App\nThe [`Application`](./src/main/java/com/gazbert/mongosample/Application.java) simply creates some\nUsers and dummy [SIP](https://en.wikipedia.org/wiki/Session_Initiation_Protocol) Registrations, and \nthen fetches them. Check out the [app.log](#logging) file.\n\nFrom the the app from the project root folder using:\n\n* Gradle - `./gradlew bootRun`\n* Maven - `./mvnw spring-boot:run`\n\nOnce you've run the app, you can take a look at the collections in the database using the Mongo Shell.\n\nTo see all the Users and Registrations:\n\n```\nshow dbs\nuse sample-app\ndb.user.find()\ndb.registration.find()\n```\n\nThe [Mongo Shell Manual](https://docs.mongodb.com/manual/crud/) lists other useful commands.\n\n### Noteworthy stuff\n\n#### The MongoTemplate\nSpring Data MongoDB uses the MongoTemplate to execute the queries behind the generated `find*` methods.\nYou can use the template directly for more complex queries - see the\n[`CustomRegistrationRepositoryImpl`](./src/main/java/com/gazbert/mongosample/repository/CustomRegistrationRepositoryImpl.java).\n\n#### Indexes\nYou can use the\n[`@Indexed`](https://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/index/Indexed.html) \nannotation on domain objects like \n[`Registration`](./src/main/java/com/gazbert/mongosample/model/Registration.java) class.\n \nTo see the indexes on the collections:\n```\ndb.user.getIndexes()\ndb.registration.getIndexes()\n```\n\n## Logging\nLogging for the app is provided by [log4j](http://logging.apache.org/log4j). \nThe log file is written to `logs/app.log` using a rolling policy. When a log file size reaches \n100 MB or a new day is started, it is archived and a new log file is created. \n\nThe app will create up to 7 archives on the same day; these are stored in a directory based on the \ncurrent year and month. Only the last 90 archives are kept. Each archive is compressed using gzip.\n\nThe logging level is set at `info`. You can change this default logging configuration in \nthe [`config/log4j2.xml`](./config/log4j2.xml) file.\n\n## Issue \u0026 Change Management\nIssues and new features are managed using the project \n[Issue Tracker](https://github.com/gazbert/spring-boot-mongodb-app/issues) - submit bugs here.\n \nYou are welcome to take on new features or fix bugs! See [here](CONTRIBUTING.md) for how to get involved. \n\n## References\n1. [MongoDB Manual](https://docs.mongodb.com/manual/reference/).\n1. [Spring Data MongoDB Reference Docs](https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#reference).\n1. [MongoDB Docker image](https://hub.docker.com/_/mongo).\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgazbert%2Fspring-boot-mongodb-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgazbert%2Fspring-boot-mongodb-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgazbert%2Fspring-boot-mongodb-app/lists"}