Hướng dẫn setup môi trường và start project
1. Mục tiêu
Hướng dẫn developer:
-
Cài đặt môi trường chạy project
-
Cấu hình biến môi trường
-
Khởi động project Spring Boot
-
Kiểm tra project chạy thành công
2. Yêu cầu hệ thống
2.1. Phần mềm cần cài đặt
| Công cụ | Phiên bản khuyến nghị |
|---|---|
| Java JDK | 17 hoặc 21 |
| Maven | 3.8+ |
| Git | Mới nhất |
| IDE | IntelliJ IDEA |
2.2. Kiểm tra cài đặt
Mở terminal:
Kết quả mong muốn:
Kiểm tra Maven:
3. Clone source code
4. Cấu hình biến môi trường
Project sử dụng file:
4.1. Các biến môi trường cơ bản
Ví dụ file:
#spring.application.name=demo
#server.port=8080
#
## ===== Oracle datasource =====
#spring.datasource.url=jdbc:oracle:thin:@//192.168.0.111:1111/ORCLPDB1
#spring.datasource.username=test
#spring.datasource.password=test
#spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
#
## ===== JPA =====
#spring.jpa.hibernate.ddl-auto=none
#spring.jpa.show-sql=true
#spring.jpa.properties.hibernate.format_sql=true
#spring.jpa.database-platform=org.hibernate.dialect.OracleDialect
#
## ===== Hikari pool (optional) =====
#spring.datasource.hikari.maximum-pool-size=10
#spring.datasource.hikari.minimum-idle=2
#spring.datasource.hikari.connection-timeout=30000
#
#management.endpoints.web.exposure.include=health,info
4.2. Cách chỉnh sửa biến môi trường
Cách 1: Sửa trực tiếp trong file application.properties
Ví dụ đổi DB:
Cách 2: Dùng biến môi trường hệ điều hành
Ví dụ trong application.properties:
Trên Windows (PowerShell)
Trên Linux/Mac
5. Chọn profile chạy
Spring Boot thường dùng profile:
Ví dụ chạy với profile dev.
Cách cấu hình profile
Cách 1: Trong biến môi trường
Windows:
Linux/Mac:
Cách 2: Trong IDE
VM options:
6. Build project
Trong thư mục project:
Nếu build thành công sẽ thấy:
7. Start project
Chạy trong IDE
Trong IntelliJ:
-
Mở project
-
Mở file:
-
Nhấn nút Run
8. Kiểm tra project chạy thành công
Sau khi start, kiểm tra log:
Mở trình duyệt:
Hoặc gọi API: