Skip to content

Commit 24292b1

Browse files
authored
Add Spring Boot Documentation (#1274)
1 parent 69bd7a3 commit 24292b1

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

docs/app/docs/devbox_examples/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ These examples combine configuration from multiple examples to create a full sta
4141
* [LAPP (Linux, Apache, PostgreSQL, PHP)](stacks/lapp.md)
4242
* [LEPP (Linux, NGINX, PostgreSQL, PHP)](stacks/lepp.md)
4343
* [Ruby on Rails](stacks/rails.md)
44+
* [Spring Boot](stacks/spring.md)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: Spring Boot
3+
description: An example of a Nix-powered Spring Boot Java application with Devbox
4+
---
5+
6+
This example combines Java, Spring Boot, and MySQL to expose a simple REST API. This example is based on the official [Spring Boot Documentation](https://spring.io/guides/gs/accessing-data-mysql/).
7+
8+
[Example Repo](https://github.com/jetpack-io/devbox/tree/main/examples/stacks/spring)
9+
10+
## How to Run
11+
12+
1. Install [Devbox](https://www.jetpack.io/devbox/docs/installing_devbox/)
13+
14+
1. Prepare the database by running `devbox run setup_db`. This will create the user and database that Spring expects in `stacks/spring/src/main/resources/application.properties`
15+
1. You can now start the Spring Boot service by running `devbox run bootRun`. This will start your MySQL service and run the application
16+
1. You can test the service using `GET localhost:8080/demo/all` or `POST localhost:8080/demo/add`. See the Spring Documentation for more details.
17+
18+
## How to Recreate this Example
19+
20+
1. Create a blank Devbox project with `devbox init`
21+
2. Add the required packages with `devbox add jdk@17 mysql@latest gradle@latest`
22+
3. Create a new Spring Boot application using the [Spring Boot initializer](https://start.spring.io/).
23+
4. Copy the devbox.json and devbox.lock files into the project directory.
24+
5. Initialize your mysql database by running `devbox services up`, and create the example DB and user using the `setup_db.sql` file in this directory.
25+
26+
## Notes
27+
28+
- This example uses the [Spring Boot initializer](https://start.spring.io/) to create the project. You can use any method you like to create your Spring Boot project, but you will need to make sure that the `devbox.json` and `devbox.lock` files are in the same directory as your `build.gradle` file.
29+
- This example hardcodes a username and password for development purposes. For production or more secure usecases, you should change them and exclude them from source control.
30+
- This distribution uses the OpenJDK. You can find other JDK distributions using `devbox search`

examples/stacks/spring/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,17 @@ This example combines Java, Spring Boot, and MySQL to expose a simple REST API.
99
1. Prepare the database by running `devbox run setup_db`. This will create the user and database that Spring expects in `stacks/spring/src/main/resources/application.properties`
1010
1. You can now start the Spring Boot service by running `devbox run bootRun`. This will start your MySQL service and run the application
1111
1. You can test the service using `GET localhost:8080/demo/all` or `POST localhost:8080/demo/add`. See the Spring Documentation for more details.
12+
13+
## How to Recreate this Example
14+
15+
1. Create a blank Devbox project with `devbox init`
16+
2. Add the required packages with `devbox add jdk@17 mysql@latest gradle@latest`
17+
3. Create a new Spring Boot application using the [Spring Boot initializer](https://start.spring.io/).
18+
4. Copy the devbox.json and devbox.lock files into the project directory.
19+
5. Initialize your mysql database by running `devbox services up`, and create the example DB and user using the `setup_db.sql` file in this directory.
20+
21+
## Notes
22+
23+
- This example uses the [Spring Boot initializer](https://start.spring.io/) to create the project. You can use any method you like to create your Spring Boot project, but you will need to make sure that the `devbox.json` and `devbox.lock` files are in the same directory as your `build.gradle` file.
24+
- This example hardcodes a username and password for development purposes. For production or more secure usecases, you should change them and exclude them from source control.
25+
- This distribution uses the OpenJDK. You can find other JDK distributions using `devbox search`

0 commit comments

Comments
 (0)