Dự án Spring Boot 3 với Spring MVC, Spring Data JPA, PostgreSQL và Hazelcast.
- Spring Boot 3.5.7
- Java 17
- Spring MVC - REST API
- Spring Data JPA - ORM
- PostgreSQL 16 - Database
- Hazelcast 5.4.0 - Distributed caching
- Lombok - Giảm boilerplate code
- Maven - Build tool
spring-playground/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/example/springplayground/
│ │ │ ├── config/ # Hazelcast configuration
│ │ │ ├── controller/ # REST Controllers
│ │ │ ├── entity/ # JPA Entities
│ │ │ ├── repository/ # Spring Data Repositories
│ │ │ └── SpringPlaygroundApplication.java
│ │ └── resources/
│ │ └── application.yml # Application configuration
│ └── test/
├── docker-compose.yml # Docker services
├── pom.xml # Maven dependencies
└── README.md
- Java 17 hoặc cao hơn
- Maven 3.6+
- Docker và Docker Compose
docker-compose up -dServices sẽ được khởi động:
- PostgreSQL:
localhost:5432 - Hazelcast:
localhost:5701
mvn spring-boot:runHoặc build và chạy:
mvn clean package
java -jar target/spring-playground-0.0.1-SNAPSHOT.jarỨng dụng sẽ chạy tại: http://localhost:8080
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/users |
Lấy danh sách tất cả users |
| GET | /api/users/{id} |
Lấy user theo ID (có cache) |
| GET | /api/users/username/{username} |
Lấy user theo username (có cache) |
| POST | /api/users |
Tạo user mới |
| PUT | /api/users/{id} |
Cập nhật user |
| DELETE | /api/users/{id} |
Xóa user |
Tạo user mới:
curl -X POST http://localhost:8080/api/users \
-H "Content-Type: application/json" \
-d '{
"username": "john_doe",
"email": "[email protected]"
}'Lấy user theo ID:
curl http://localhost:8080/api/users/1Lấy tất cả users:
curl http://localhost:8080/api/usersspring:
datasource:
url: jdbc:postgresql://localhost:5432/springdb
username: postgres
password: postgres- Cache được enable với annotation
@EnableCaching - Sử dụng Hazelcast làm cache provider
- Các method có annotation
@Cacheablesẽ được cache tự động - Cache được clear khi có update/delete với
@CacheEvict
docker exec -it spring-postgres psql -U postgres -d springdbcurl http://localhost:5701/hazelcast/healthdocker-compose downXóa cả volumes (dữ liệu sẽ mất):
docker-compose down -vmvn clean installmvn testmvn spring-javaformat:applyMIT License