-
Notifications
You must be signed in to change notification settings - Fork 248
Add a Java Spring Boot Example #1261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,12 @@ | |
"lockfile_version": "1", | ||
"packages": { | ||
"python310": { | ||
"plugin_version": "0.0.1", | ||
"resolved": "github:NixOS/nixpkgs/f80ac848e3d6f0c12c52758c0f25c10c97ca3b62#python310" | ||
}, | ||
"[email protected]": { | ||
"last_modified": "2023-05-01T16:53:22Z", | ||
"plugin_version": "0.0.1", | ||
"resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#python310Packages.pip", | ||
"version": "23.0.1" | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Laravel | ||
|
||
Laravel is a powerful web application framework built with PHP. It's a great choice for building web applications and APIs. | ||
|
||
This example shows how to build a simple Laravel application backed by MariaDB and Redis. It uses Devbox Plugins for all 3 Nix packages to simplify configuration | ||
|
||
[](https://devbox.sh/github.com/jetpack-io/devbox/?folder=examples/stacks/laravel) | ||
|
||
## How to Run | ||
|
||
1. Install [Devbox](https://www.jetpack.io/devbox/docs/installing_devbox/) | ||
|
||
1. Create a new Laravel App by running `devbox create --template laravel`. This will create a new Laravel project in your current directory. | ||
|
||
1. Start your MariaDB and Redis services by running `devbox services up`. | ||
1. This step will also create an empty MariaDB Data Directory and initialize your database with the default settings | ||
2. This will also start the php-fpm service for serving your PHP project over fcgi. Learn more about [PHP-FPM](https://www.php.net/manual/en/install.fpm.php) | ||
|
||
1. Create the laravel database by running `devbox run db:create`, and then run Laravel's initial migrations using `devbox run db:migrate` | ||
|
||
1. You can now start the artisan server by running `devbox run serve:dev`. This will start the server on port 8000, which you can access at `localhost:8000` | ||
|
||
1. If you're using Laravel on Devbox Cloud, you can test the app by appending `/port/8000` to your Devbox Cloud URL | ||
|
||
1. For more details on building and developing your Laravel project, visit the [Laravel Docs](https://laravel.com/docs/10.x) | ||
|
||
|
||
## How to Recreate this Example | ||
|
||
### Creating the Laravel Project | ||
|
||
1. Create a new project with `devbox init` | ||
|
||
2. Add the packages using the command below. Installing the packages with `devbox add` will ensure that the plugins are activated: | ||
|
||
```bash | ||
devbox add mariadb@latest, [email protected], nodejs@18, redis@latest, php81Packages.composer@latest | ||
``` | ||
|
||
3. Run `devbox shell` to start your shell. This will also initialize your database by running `initdb` in the init hook. | ||
|
||
4. Create your laravel project by running: | ||
|
||
```bash | ||
composer create-project laravel/laravel tmp | ||
|
||
mv tmp/* tmp/.* . | ||
``` | ||
|
||
### Setting up MariaDB | ||
|
||
To use MariaDB, you need to create the default Laravel database. You can do this by running the following commands in your `devbox shell`: | ||
|
||
```bash | ||
# Start the MariaDB service | ||
devbox services up mariadb -b | ||
|
||
# Create the database | ||
mysql -u root -e "CREATE DATABASE laravel;" | ||
|
||
# Once you're done, stop the MariaDB service | ||
devbox services stop mariadb | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
HELP.md | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Spring Boot Example | ||
|
||
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/). | ||
|
||
## How to Run | ||
|
||
1. Install [Devbox](https://www.jetpack.io/devbox/docs/installing_devbox/) | ||
|
||
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` | ||
1. You can now start the Spring Boot service by running `devbox run bootRun`. This will start your MySQL service and run the application | ||
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.springframework.boot' version '3.1.1' | ||
id 'io.spring.dependency-management' version '1.1.0' | ||
} | ||
|
||
group = 'com.devbox.example.spring' | ||
version = '0.0.1-SNAPSHOT' | ||
|
||
java { | ||
sourceCompatibility = '17' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
implementation 'org.springframework.boot:spring-boot-starter-data-redis' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
runtimeOnly 'com.mysql:mysql-connector-j' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
} | ||
|
||
tasks.named('test') { | ||
useJUnitPlatform() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"packages": [ | ||
"jdk@17", | ||
"gradle@latest", | ||
"mysql80@latest" | ||
], | ||
"shell": { | ||
"init_hook": [ | ||
"echo 'Welcome to devbox!'\n", | ||
"echo 'Setup MySQL by running `devbox run setup_db`", | ||
"echo 'Run the example using `devbox run bootRun" | ||
], | ||
"scripts": { | ||
"bootRun": [ | ||
"devbox services up -b", | ||
"./gradlew bootRun", | ||
"devbox services stop" | ||
], | ||
"build": [ | ||
"./gradlew build" | ||
], | ||
"setup_db": [ | ||
"devbox services up mysql -b", | ||
"mysql -u root < setup_db.sql", | ||
"devbox services stop" | ||
], | ||
"test": [ | ||
"./gradlew test" | ||
] | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"lockfile_version": "1", | ||
"packages": { | ||
"gradle@latest": { | ||
"last_modified": "2023-06-29T16:20:38Z", | ||
"plugin_version": "0.0.1", | ||
"resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#gradle", | ||
"version": "8.0.1" | ||
}, | ||
"jdk@17": { | ||
"last_modified": "2023-06-29T16:20:38Z", | ||
"resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#jdk17", | ||
"version": "17.0.7+7" | ||
}, | ||
"mysql80@latest": { | ||
"last_modified": "2023-06-29T16:20:38Z", | ||
"plugin_version": "0.0.1", | ||
"resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#mysql80", | ||
"version": "8.0.33" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.gradle.java.home=/nix/store/csfdcflywb9gj20b1mvsp1ixy6f398bg-zulu17.34.19-ca-jdk-17.0.3 |
Binary file not shown.
6 changes: 6 additions & 0 deletions
6
examples/stacks/spring/gradle/wrapper/gradle-wrapper.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip | ||
networkTimeout=10000 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this jar file isn't needed and can be deleted