English | 简体中文
A lightweight and easy-to-use Spring Boot startup template, based on Spring Boot 2.7.0.
- developers who find Spring Boot too complex
- developers who want a fast application startup
Useful for customization before and after IOC bean creation, eg. decide whether to init db connection.
Hook Name | Desc |
---|---|
BeforeBeanInitHook | before spring ioc bean initialization |
AfterBeanInitHook | after spring ioc bean initialization |
beforeMvcRequest
→ handleEx/handleExtraEx
→ beforeWritingBody
→ afterMvcRequest
Hook Name | Desc |
---|---|
beforeMvcRequest | before mvc request |
handleEx/handleExtraEx | handle mvc exceptions |
beforeWritingBody | before writing response body |
afterMvcRequest | after mvc request |
-
Dynamic Table Name: Dynamically build table names based on runtime context.
-
Conditional Index Creation: Conditionally create database indexes when needed.
Basic Usage
Support serving vue2js
, next.js
.
java -jar xx.jar --serve_static="/path/to/static/"
- serve_static: specify a static folder on the filesystem to serve.
value "/path/to/static/" good "/path/to/static" bad: not end with "/" "path/to/static" bad: not start with "/"
Start using docker compose
staticserver/
├── server.jar
├── docker-compose.yml
├── .env(optional)
└── static/
└── index.html
docker-compose.yml
version: "3.8"
services:
staticserver:
image: eclipse-temurin:8-alpine
container_name: "${CONTAINER_NAME:-staticserver}"
restart: always
ports:
- "${LOCAL_PORT:-8080}:8080"
volumes:
- "${SERVER_JAR:-./server.jar}:/server.jar"
- "${STATIC_LOCATION:-./static}:/static"
command: >
java -Dfile.encoding=UTF-8 -jar /server.jar
--serve_mode="nextjs"
--serve_static="/static/"
.env
CONTAINER=staticserver
LOCAL_PORT=8080
STATIC_LOCATION=custom/static
SERVER_JAR=custom/server.jar
start static server
docker compose \
-f ${staticserver}/docker-compose.yml \
up -d
stop static server
docker compose \
-f ${staticserver}/docker-compose.yml \
down
-
clone the project:
mkdir -p ~/projects cd ~/projects git clone git@github.com:ArcaneEcholan/easy-spring-template.git cd easy-spring-template
-
use jdk8 to compile
-
run
App.java
-
Set
db.enabled: true
. -
Start Database with docker:
sudo docker compose -f ./docker-compose-db.yml up -d
-
Configure db properties at:
src/main/resources/application.yml
:# ============== custom ============== db: enabled: true user: root password: root name: test host: localhost port: 33061
This project is licensed under the MIT License.