Throyer/springboot-api-rest-example
关于
Spring Boot API RESTful with tests, swagger e JWT 🚀
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- +1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文🚨 I'm working on a migration to
spring boot 3, it's not completely done yet, but the branch is this: https://github.com/Throyer/springboot-api-rest-example/tree/spring-boot-3-migration the focus is on making the experience with docker better, 100% test coverage, the rate-limit is in an nginx container and most of the configurations I tried to simplify
Spring Boot API RESTful
A complete user registry, with access permissions, JWT token, integration and unit tests, using the RESTful API pattern.
Table of Contents
- Features
- Requirements
- Docker
- Local installation
- Entities
- Running a specific test
- Swagger
- Database Migrations
- Environment variables
Features
Requirements
- Postgres:
^13 - Java:
^17 - Maven:
^3.8.4
This project was started with Spring Initializr.
Entities
Docker examples
🚨 create
environmentfile and add permission to execute scriptscp .docker/.env.example .docker/.env && chmod -R +x .docker/scripts
docker-compose for development
- starting containers
.docker/scripts/develop up -d --build- removing contaiers
.docker/scripts/develop down- show backend logs
.docker/scripts/develop logs -f apidocker-compose for production
.docker/scripts/production up -d --build.docker/scripts/production down
Local Installation
🚨 check requirements or if you are using docker check docker development instructions
- clone the repository and access the directory.
git clone [email protected]:Throyer/springboot-api-crud.git crud && cd crud - download dependencies
mvn -f api/pom.xml install -DskipTests - run the application (available at: localhost:8080)
mvn -f api/pom.xml spring-boot:run - running the tests
mvn -f api/pom.xml test - to build for production
mvn -f api/pom.xml clean package - to generate the coverage report after testing
(available at: api/target/site/jacoco/index.html)mvn -f api/pom.xml jacoco:report
Tests
Running a specific test
use the parameter -Dtest=<class>#<method>
- for example the integration test. creating a user:
mvn -f api/pom.xml test -Dtest=UsersControllerTests#should_save_a_new_user
Swagger
Once the application is up, it is available at: localhost:8080/docs
🚨 if you set
SWAGGER_USERNAMEandSWAGGER_PASSWORDon application.properties file this route require authentication
Database Migrations
Creating database migration files
🚨 check requirements
if you using docker-compose
.docker/scripts/mvn migration:generate -Dname=my-migration-name
Java based migrations
mvn -f api/pom.xml migration:generate -Dname=my-migration-nameSQL based migrations
mvn -f api/pom.xml migration:generate -Dname=my-migration-name -Dsql
Environment variables
| Description | Parameter | Default values |
|---|---|---|
| server port | SERVER_PORT |
8080 |
| database host | DB_HOST |
localhost |
| database port | DB_PORT |
5432 |
| database name | DB_NAME |
example |
| database username | DB_USERNAME |
root |
| database user password | DB_PASSWORD |
root |
| displays the generated sql in the logger | DB_SHOW_SQL |
false |
| set maximum database connections | DB_MAX_CONNECTIONS |
5 |
| secret value in token generation | TOKEN_SECRET |
secret |
| secret hash ids | HASHID_SECRET |
secret |
| token expiration time in hours | TOKEN_EXPIRATION_IN_HOURS |
24 |
| refresh token expiry time in days | REFRESH_TOKEN_EXPIRATION_IN_DAYS |
7 |
| SMTP server address | SMTP_HOST |
smtp.gmail.com |
| SMTP server port | SMTP_PORT |
587 |
| SMTP username | SMTP_USERNAME |
user |
| SMTP server password | SMTP_PASSWORD |
secret |
| time for recovery email to expire | MINUTES_TO_EXPIRE_RECOVERY_CODE |
20 |
| max requests per minute | MAX_REQUESTS_PER_MINUTE |
50 |
| swagger url | SWAGGER_URL |
/docs |
| swagger username | SWAGGER_USERNAME |
null |
| swagger password | SWAGGER_PASSWORD |
null |
these variables are defined in: application.properties
# to change the value of some environment variable at runtime # on execution, just pass it as a parameter. (like --SERVER_PORT=80). $ java -jar api-5.0.0.jar --SERVER_PORT=80
Star History
探索相关项目
加载中…


