Spring Boot
This example combines Java, Spring Boot, and MySQL to expose a simple REST API. This example is based on the official Spring Boot Documentation.
How to Run
-
Install Devbox
-
Prepare the database by running
devbox run setup_db
. This will create the user and database that Spring expects instacks/spring/src/main/resources/application.properties
-
You can now start the Spring Boot service by running
devbox run bootRun
. This will start your MySQL service and run the application -
You can test the service using
GET localhost:8080/demo/all
orPOST localhost:8080/demo/add
. See the Spring Documentation for more details.
How to Recreate this Example
- Create a blank Devbox project with
devbox init
- Add the required packages with
devbox add jdk@17 mysql@latest gradle@latest
- Create a new Spring Boot application using the Spring Boot initializer.
- Copy the devbox.json and devbox.lock files into the project directory.
- Initialize your mysql database by running
devbox services up
, and create the example DB and user using thesetup_db.sql
file in this directory.
Notes
- This example uses the Spring Boot initializer 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
anddevbox.lock
files are in the same directory as yourbuild.gradle
file. - 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.
- This distribution uses the OpenJDK. You can find other JDK distributions using
devbox search