Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/CleverCloud/springboot-mongo-example

Run Spring Boot with MongoDB on Clever Cloud
https://github.com/CleverCloud/springboot-mongo-example

clevercloud-example mongodb spring-boot

Last synced: about 1 month ago
JSON representation

Run Spring Boot with MongoDB on Clever Cloud

Awesome Lists containing this project

README

        

# Spring Boot as RESTful Demo for Clever-Cloud

## Description

This is a small Spring Boot app that uses java + maven Clever Cloud application type.

This is a RESTful app which is using the MongoDB addon.

## Features

As a RESTful you can use HTTP requests like:

- `GET /users`
- `GET /users/{userId}`
- `POST /users "body": {"firstName":"Robert", "lastName":"Cloud"}`
- `DELETE /users/{userId}`

## Model

```json
"users":[
{
"id" : "...",
"firstName" : "...",
"lastName" : "..."
}
]
```

## Configuration

### MongoDB

MongoDB URI is set in `src/main/resources/application.properties` and looks like:

```java
spring.data.mongodb.uri=${MONGODB_ADDON_URI}
```

Where `MONGODB_ADDON_URI` is an environment variable which is specified by MongoDB addon link.

## Install and run locally

- install dependencies: `mvn install`
- tests: `mvn test`
- run: `mvn spring-boot:run`

## Deploy on the Clever Cloud console

Create a mongodb add-on and link it to your app.

### Set the goal in the environment

In the environment variables, create `MAVEN_DEPLOY_GOAL` and set it to `spring-boot:run`

## Example

Create new user

```bash
curl -d '{"firstName":"Robert", "lastName":"Cloud"}' -H "Content-Type: application/json" -X POST https://.cleverapps.io/users
```

Get users list

```bash
curl -X GET https://.cleverapps.io/users
```

Find user by id

```bash
curl -X GET https://.cleverapps.io/users/
```

Remove user by id

```bash
curl -X DELETE https://.cleverapps.io/users/
```

## Test

I wrote an example of test in `src/test/java/com/cc/demo/test/UserMongoRepositoryTest.java` which is called during `mvn test`.